Skip to content

Commit 533606e

Browse files
committed
add woql test
1 parent 4b2b97b commit 533606e

File tree

8 files changed

+116
-55
lines changed

8 files changed

+116
-55
lines changed

dist/terminus-client.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/terminus-client.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/framePattern.js

Lines changed: 52 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,3 @@
1-
/**
2-
* FramePatternMatcher does pattern matching on frames
3-
* Does a given pattern match a given frame?
4-
*/
5-
const FramePatternMatcher = {}
6-
7-
/**
8-
* Runs an array of matching rules across a frame and calls the passed onmatch function on each match
9-
* The optional onmatch function is called with each hit and is passed the frame and the rule that hit it.
10-
* A list of the matched rules is returned.
11-
*
12-
*/
13-
FramePatternMatcher.testRules = function(rules, frame, onmatch){
14-
var matched_rules = [];
15-
if(rules && rules.length){
16-
for(var i = 0; i<rules.length; i++){
17-
var match = (!rules[i].rule.pattern || FramePatternMatcher.patternMatchesFrame(rules[i].rule.pattern, frame));
18-
if(match){
19-
matched_rules.push(rules[i]);
20-
if(onmatch && typeof onmatch == "function"){
21-
onmatch(frame, rules[i]);
22-
}
23-
}
24-
}
25-
}
26-
return matched_rules;
27-
}
28-
29-
/**
30-
* Determines whether a given pattern matches a given frame
31-
*/
32-
FramePatternMatcher.patternMatchesFrame = function(pattern, frame){
33-
if(typeof pattern == "object" && pattern.length){ //multiple patterns are ANDed
34-
for(var i = 0 ; i<pattern.length; i++){
35-
var fp = new FramePattern(pattern[i]);
36-
if(!fp.checkFrame(frame)) return false;
37-
}
38-
return true;
39-
}
40-
else {
41-
var fp = new FramePattern(pattern);
42-
return fp.checkFrame(frame);
43-
}
44-
}
45-
46-
471
/**
482
* A frame pattern can have the following variables
493
* renderer : object, property, data, * - matches a specific part of the frame
@@ -61,7 +15,7 @@ FramePatternMatcher.patternMatchesFrame = function(pattern, frame){
6115
* status: updated, error, new, ok,
6216
*/
6317

64-
FramePattern = function(pattern){
18+
function FramePattern(pattern){
6519
if(pattern){
6620
this.setPattern(pattern);
6721
}
@@ -301,6 +255,57 @@ FramePattern.prototype.getRendererType = function(frame){
301255
return false;
302256
}
303257

258+
259+
260+
261+
262+
/**
263+
* FramePatternMatcher does pattern matching on frames
264+
* Does a given pattern match a given frame?
265+
*/
266+
const FramePatternMatcher = {}
267+
268+
/**
269+
* Runs an array of matching rules across a frame and calls the passed onmatch function on each match
270+
* The optional onmatch function is called with each hit and is passed the frame and the rule that hit it.
271+
* A list of the matched rules is returned.
272+
*
273+
*/
274+
FramePatternMatcher.testRules = function(rules, frame, onmatch){
275+
var matched_rules = [];
276+
if(rules && rules.length){
277+
for(var i = 0; i<rules.length; i++){
278+
var match = (!rules[i].rule.pattern || FramePatternMatcher.patternMatchesFrame(rules[i].rule.pattern, frame));
279+
if(match){
280+
matched_rules.push(rules[i]);
281+
if(onmatch && typeof onmatch == "function"){
282+
onmatch(frame, rules[i]);
283+
}
284+
}
285+
}
286+
}
287+
return matched_rules;
288+
}
289+
290+
/**
291+
* Determines whether a given pattern matches a given frame
292+
*/
293+
FramePatternMatcher.patternMatchesFrame = function(pattern, frame){
294+
if(typeof pattern == "object" && pattern.length){ //multiple patterns are ANDed
295+
for(var i = 0 ; i<pattern.length; i++){
296+
var fp = new FramePattern(pattern[i]);
297+
if(!fp.checkFrame(frame)) return false;
298+
}
299+
return true;
300+
}
301+
else {
302+
var fp = new FramePattern(pattern);
303+
return fp.checkFrame(frame);
304+
}
305+
}
306+
307+
308+
304309
function FrameRule(){
305310
this.rule = { pattern: {} };
306311
return this;

lib/woqlClient.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const UTILS = require('./utils.js');
1818
function WOQLClient(params) {
1919
// current connection context variables
2020
const key = params ? params.key : undefined;
21-
this.use_fetch = true;
21+
this.use_fetch = false;
2222
this.return_full_response = false;
2323
this.connectionConfig = new ConnectionConfig(params);
2424
this.connection = new ConnectionCapabilities(this.connectionConfig, key);

package-lock.json

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"babel-eslint": "^10.0.3",
2121
"babel-loader": "^8.0.6",
2222
"chai": "^4.2.0",
23+
"chai-json-equal": "0.0.1",
2324
"coveralls": "^3.0.6",
2425
"cross-env": "^5.2.1",
2526
"eslint": "^5.16.0",

test/woql.spec.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//const chai =require('chai');
2+
const expect = require('chai').expect;
3+
4+
//const chaiJsonEqual = require('chai-json-equal');
5+
6+
var WOQL = require('../lib/woql');
7+
8+
//chai.use(chaiJsonEqual);
9+
10+
describe('woql queries', function () {
11+
12+
13+
it('check the start properties values',function(){
14+
15+
const woqlObject=WOQL.query();
16+
expect(woqlObject.chain_ended).to.equal(false);
17+
expect(woqlObject.contains_update).to.equal(false);
18+
expect(woqlObject.vocab.type).to.equal('rdf:type');
19+
})
20+
21+
22+
it('check the limit method',function(){
23+
24+
const woqlObject=WOQL.limit(10);
25+
//{ limit: [ 10, {} ] }
26+
27+
//console.log(woqlObject.json());
28+
29+
expect(woqlObject.json().limit[0]).to.equal(10);
30+
31+
//chai.should(woqlObject.json()).jsonEqual({ limit: [ 10, {} ] });
32+
33+
expect(woqlObject.json()).to.eql({ limit: [ 10, {} ] });
34+
35+
})
36+
37+
it('check the start method',function(){
38+
//{ limit: [ 10, { start: [Array] } ] }
39+
const woqlObject=WOQL.limit(10).start(0);
40+
41+
const jsonObj={"limit": [10,{"start": [0,{}]}]}
42+
43+
//console.log(JSON.stringify(woqlObject.json(),null,2))
44+
45+
expect(woqlObject.json()).to.eql(jsonObj);
46+
47+
})
48+
49+
})

test/woqlQuery.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
'use strict'
1+
/*'use strict'
22
const axios = require("axios");
33
const expect = require('chai').expect;
44
const allClassQuery=`select([v('Class'), v('Label'), v('Comment'),
@@ -18,6 +18,6 @@ describe('woql query', function () {
1818
1919
done();
2020
})
21-
})
21+
})*/
2222
//someText = someText.replace(/(\r\n|\n|\r)/gm, "");
2323

0 commit comments

Comments
 (0)