Skip to content

Commit f0b10dc

Browse files
committed
Update test and clean up woql.js
1 parent d084f9c commit f0b10dc

File tree

2 files changed

+55
-21
lines changed

2 files changed

+55
-21
lines changed

lib/woql.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ WOQL.query = function(){ return new WOQLQuery(); }
9191
//loads query from json
9292
WOQL.json = function(json){ return new WOQLQuery().json(json); }
9393

94-
WOQL.rule = function(type){
95-
if(type && type == "frame") return new FrameRule();
96-
return new WOQLRule();
94+
WOQL.rule = function(type){
95+
if(type && type == "frame") return new FrameRule();
96+
return new WOQLRule();
9797
}
9898
WOQL.getMatchingRules = function(rules, row, key, context, action){
9999
return new WOQLRule().getMatchingRules(rules, row, key, context, action);
@@ -110,7 +110,7 @@ WOQL.insert = function(Node, Type, Graph){
110110
}
111111

112112
WOQL.doctype = function(Type, Graph){
113-
return new WOQLQuery().add_class(Type, Graph).parent("Document");
113+
return new WOQLQuery().add_class(Type, Graph).parent("Document");
114114
}
115115

116116

@@ -217,7 +217,7 @@ WOQLQuery.prototype.order_by = function(gvarlist, asc_or_desc, query){
217217
const vars = UTILS.addNamespacesToVariables(ordering);
218218
asc_or_desc = asc_or_desc || "asc";
219219
ordering = {};
220-
ordering[asc_or_desc] = vars;
220+
ordering[asc_or_desc] = vars;
221221
}
222222
this.advanceCursor("order_by", ordering);
223223
if(query){
@@ -812,7 +812,7 @@ WOQLQuery.prototype.property = function(p,val){
812812
var nwoql = WOQL.add_property(p, val).domain(this.adding_class);
813813
nwoql.query.and.push(this.json());
814814
nwoql.adding_class = this.adding_class;
815-
return nwoql;
815+
return nwoql;
816816
}
817817
else {
818818
p = this.cleanPredicate(p);
@@ -821,7 +821,7 @@ WOQLQuery.prototype.property = function(p,val){
821821
}
822822
return this;
823823
}
824-
824+
825825
WOQLQuery.prototype.star = function(GraphIRI, Subj, Pred, Obj){
826826
Subj = (Subj ? this.cleanSubject(Subj) : "v:Subject");
827827
Pred = (Pred ? this.cleanPredicate(Pred) : "v:Predicate");
@@ -831,12 +831,12 @@ WOQLQuery.prototype.star = function(GraphIRI, Subj, Pred, Obj){
831831
return this.quad(Subj, Pred, Obj, GraphIRI);
832832
}
833833
else {
834-
console.log(Subj, Pred, Obj);
834+
//console.log(Subj, Pred, Obj);
835835
return this.triple(Subj, Pred, Obj);
836836
}
837837
}
838838

839-
/**
839+
/**
840840
* These are composite functions, the above are primitives
841841
*/
842842
WOQLQuery.prototype.getEverything = function(GraphIRI){

test/woql.spec.js

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,37 @@ describe('woql queries', function () {
1313
expect(woqlObject.vocab.type).to.equal('rdf:type');
1414
})
1515

16+
it('check the insert method',function(){
17+
18+
const woqlObject=WOQL.insert("v:Bike_URL", "Bicycle");
19+
const woqlObjectDB=WOQL.insert("v:Bike_URL", "Bicycle", "myDB");
20+
const jsonObj={ "add_triple": [ 'v:Bike_URL', 'rdf:type', 'scm:Bicycle' ] };
21+
const jsonObjDB={ "add_quad": [ 'v:Bike_URL', 'rdf:type', 'scm:Bicycle', 'db:myDB' ] };
22+
expect(woqlObject.json()).to.eql(jsonObj);
23+
expect(woqlObjectDB.json()).to.eql(jsonObjDB);
24+
})
25+
26+
it('check the doctype method',function(){
27+
28+
const woqlObject=WOQL.doctype("Station");
29+
30+
const jsonObj={ "and": [
31+
{ "add_quad": ["scm:Station",
32+
"rdf:type",
33+
"owl:Class",
34+
"db:schema"] },
35+
{ "add_quad": ["scm:Station",
36+
"rdfs:subClassOf",
37+
"tcs:Document",
38+
"db:schema"] }
39+
] }
40+
41+
expect(woqlObject.json()).to.eql(jsonObj);
42+
43+
})
1644

1745
it('check the limit method',function(){
18-
const woqlObject=WOQL.limit(10);
46+
const woqlObject=WOQL.limit(10);
1947

2048
expect(woqlObject.json().limit[0]).to.equal(10);
2149

@@ -70,14 +98,10 @@ describe('woql queries', function () {
7098

7199
it('check the when method',function(){
72100

73-
<<<<<<< HEAD
74-
const woqlObject=WOQL.when(true, WOQL.addClass("id"));
75-
=======
76101
const Update=WOQL.add_class("id");
77102
const Condition=WOQL.or(WOQL.triple("a", "b", "c"),WOQL.triple("1", "2", "3"));
78103

79104
const woqlObject=WOQL.when(true, WOQL.add_class("id"));
80-
>>>>>>> 37c8029e275df396c6d0a0dc5c6f76309dd398fd
81105

82106
const woqlObjectChain=WOQL.when(true).add_class("id")
83107

@@ -115,7 +139,7 @@ describe('woql queries', function () {
115139

116140
const woqlObjectChain=WOQL.from("http://dburl").limit(10);
117141

118-
const jsonObj={ from: [ 'http://dburl', { limit: [ 10, {} ] } ] }
142+
const jsonObj={ "from": [ 'http://dburl', { "limit": [ 10, {} ] } ] }
119143

120144
//expect(woqlObject.json()).to.eql(jsonObj);
121145
expect(woqlObjectChain.json()).to.eql(jsonObj);
@@ -126,7 +150,7 @@ describe('woql queries', function () {
126150

127151
const woqlObject=WOQL.limit(10).star();
128152

129-
const jsonObj={ limit: [ 10, { "triple": [
153+
const jsonObj={ "limit": [ 10, { "triple": [
130154
"v:Subject",
131155
"v:Predicate",
132156
"v:Object"
@@ -287,6 +311,17 @@ describe('woql queries', function () {
287311

288312
})
289313

314+
it('check the cast method',function(){
315+
316+
const woqlObject=WOQL.cast("v:Duration", "xsd:integer", "v:Duration_Cast");
317+
318+
const jsonObj={ "typecast": [ "v:Duration", "xsd:integer", "v:Duration_Cast" ] }
319+
320+
expect(woqlObject.json()).to.eql(jsonObj);
321+
322+
})
323+
324+
290325
it('check the list method',function(){
291326

292327
const woqlObject=WOQL.list(["V1","V2"]);
@@ -686,13 +721,13 @@ describe('triple builder chaining methods', function () {
686721
{ add_triple: ["v:Node_ID", "rdfs:subClassOf", "tcs:Entity"] },
687722
{ add_triple: ["v:Node_ID", "rdfs:subClassOf", "scm:hello"] }
688723
]};
689-
expect(woqlObject.json()).to.eql(jsonObj);
724+
expect(woqlObject.json()).to.eql(jsonObj);
690725
})
691726
it('check the chained doctype method',function(){
692727
const woqlObject = WOQL.doctype("MyDoc")
693728
.property("prop", "dateTime")
694729
.property("prop2", "integer")
695-
730+
696731
const jsonObj={ and: [
697732
{ add_quad: ["scm:prop2", "rdf:type", "owl:DatatypeProperty", "db:schema"] },
698733
{ add_quad: ["scm:prop2", "rdfs:range", "xsd:integer", "db:schema"] },
@@ -706,10 +741,9 @@ describe('triple builder chaining methods', function () {
706741
{ add_quad: ["scm:MyDoc", "rdf:type", "owl:Class", "db:schema"] },
707742
{ add_quad: ["scm:MyDoc", "rdfs:subClassOf", "tcs:Document", "db:schema"] }
708743
]}
709-
]},
744+
]},
710745
]};
711-
expect(woqlObject.json()).to.eql(jsonObj);
746+
expect(woqlObject.json()).to.eql(jsonObj);
712747
})
713748

714749
})
715-

0 commit comments

Comments
 (0)