File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4,14 +4,14 @@ var pointer = require('json-pointer');
44var getJst = require ( './get_jst' ) ;
55
66module . exports = {
7- callExec : callExec ,
8- getRef : getRef ,
9- getData : getData ,
10- ifThen : ifThen
7+ eval$exec : eval$exec ,
8+ eval$ref : eval$ref ,
9+ eval$data : eval$data ,
10+ eval$if : eval$if
1111} ;
1212
1313
14- function callExec ( params ) {
14+ function eval$exec ( params ) {
1515 var $exec = params . $exec ;
1616 var $method = params . $method ;
1717 var executor = this . js . _executors [ $exec ] ;
@@ -28,19 +28,19 @@ function callExec(params) {
2828}
2929
3030
31- function getRef ( params , script , data ) {
31+ function eval$ref ( params , script , data ) {
3232
3333}
3434
3535
36- function getData ( params ) {
36+ function eval$data ( params ) {
3737 var $data = params . $data ;
3838 if ( $data [ 0 ] == '#' ) $data = decodeURIComponent ( $data . slice ( 1 ) ) ;
3939 return pointer . get ( this . data , $data ) ;
4040}
4141
4242
43- function ifThen ( params ) {
43+ function eval$if ( params ) {
4444 var script = params . $if
4545 ? params . $then
4646 : typeof params . $else == 'undefined' ? null : params . $else ;
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ function JSONScript(opts) {
2020 this . _util = util ;
2121 this . ajv = Ajv ( { passContext : true , v5 : true } ) ;
2222 this . Script = Script ;
23+
2324 addAjvKeywords . call ( this ) ;
2425 addCoreInstructions . call ( this ) ;
2526}
Original file line number Diff line number Diff line change 55 "main" : " lib/jsonscript.js" ,
66 "scripts" : {
77 "test" : " mocha spec/*.spec.js -R spec" ,
8- "test-cov" : " istanbul cover -x 'spec/**' node_modules/mocha/bin/_mocha -- spec/*.spec.js -R spec"
8+ "test-cov" : " istanbul cover -x 'spec/**' node_modules/mocha/bin/_mocha -- spec/*.spec.js -R spec" ,
9+ "test-debug" : " mocha spec/*.spec.js --debug-brk -R spec"
910 },
1011 "repository" : {
1112 "type" : " git" ,
3132 },
3233 "devDependencies" : {
3334 "istanbul" : " ^0.4.2" ,
35+ "jsonscript-test" : " ^0.1.0" ,
36+ "jsonscript-test-suite" : " ^0.1.0" ,
3437 "mocha" : " ^2.4.5"
3538 }
3639}
Load diff This file was deleted.
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ var jsonScriptTest = require ( 'jsonscript-test' ) ;
4+ var JSONScript = require ( '../lib/jsonscript' ) ;
5+ var Ajv = require ( 'ajv' ) ;
6+ var assert = require ( 'assert' ) ;
7+
8+ var js = JSONScript ( ) ;
9+
10+
11+ jsonScriptTest ( js , {
12+ only : true ,
13+ description : 'JSONScript evaluation tests' ,
14+ suites : {
15+ 'JSONScript test suite' : '../node_modules/jsonscript-test-suite/tests/{**/,}*.json' ,
16+ 'Additional tests' : './tests/{**/,}*.json'
17+ } ,
18+ afterEach : assertValidationErrors ,
19+ cwd : __dirname
20+ } ) ;
21+
22+
23+ function assertValidationErrors ( res ) {
24+ if ( res . passed && res . test . error && res . test . validationErrors ) {
25+ var e = res . error ;
26+ assert ( e instanceof Ajv . ValidationError ) ;
27+ var errors = e . errors . map ( function ( err ) { return err . message ; } ) ;
28+ assert . deepEqual ( errors , res . test . validationErrors ) ;
29+ }
30+ }
Original file line number Diff line number Diff line change 1+ [
2+ {
3+ "description" : " $data errors" ,
4+ "data" : {
5+ "foo" : 1 ,
6+ "baz" : 2
7+ },
8+ "tests" : [
9+ {
10+ "description" : " invalid JSON pointer" ,
11+ "script" : { "$data" : " foo" },
12+ "error" : " validation failed" ,
13+ "validationErrors" : [ " should match format \" json-pointer\" " ]
14+ },
15+ {
16+ "description" : " valid JSON pointer not pointing to any data" ,
17+ "script" : { "$data" : " /abc" },
18+ "error" : " Invalid reference token: abc"
19+ },
20+ {
21+ "description" : " valid JSON pointer not pointing to any data 2" ,
22+ "script" : { "$data" : " /foo/bar" },
23+ "error" : " Invalid reference token: bar"
24+ },
25+ {
26+ "description" : " valid JSON pointer is not resolvable" ,
27+ "script" : { "$data" : " /abc/baz" },
28+ "error" : " Invalid reference token: abc"
29+ }
30+ ]
31+ }
32+ ]
You can’t perform that action at this time.
0 commit comments