Skip to content

Commit

Permalink
Add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
awwright committed Jan 6, 2011
1 parent 0a399ec commit a974163
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ The finished SPARQL parser is found in sparql.js (and also symlinked by index.js
var sparqlParser=require('sparql');
var query = sparqlParser.parse(query).ref('_:query');

Some Vows tests can be run, simply run `vows` in the working directory.
15 changes: 15 additions & 0 deletions test/curie.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
var vows=require('vows');
var assert=require('assert');
var sparqlParser=require('./../sparql.js');

var p = sparqlParser.parse;


vows.describe('js3 Equality tests').addBatch(
{ 'Resolve "sp:path"': function(){ assert.equal("sp:path".resolve(), "http://spinrdf.org/sp#path"); }
, 'Resolve "path"':
{ topic: {path: "abc"}.ref('_:test')
, 'toNT()': function(t){ assert.equal(t.toNT(), '_:test <http://spinrdf.org/sp#path> "abc" .'); }
}
}
).export(module);
41 changes: 41 additions & 0 deletions test/select.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
var vows=require('vows');
var assert=require('assert');
var sparqlParser=require('./../sparql.js');

var p = sparqlParser.parse;


vows.describe('js3 Equality tests').addBatch({
'SELECT * {?x a ?z}':
{ topic: p("SELECT * {?x a ?z}").ref('_:query')
//, 'Output structure': function(t){ console.log(t); }
//, 'Output NT': function(t){ console.log(t.toNT()); }
, 'Variable list empty 1': function(t){ assert.isUndefined(t["http://spinrdf.org/sp#resultVariables"]); }
, 'Variable list empty 2': function(t){ assert.isEmpty(t["sp:resultVariables"]); }
, 'a == "http://spinrdf.org/sp#Select"': function(t){ assert.equal(t.a.resolve(), "http://spinrdf.org/sp#Select"); }
, 'a == "sp:Select"': function(t){ assert.equal(t.a, "sp:Select"); }
, 'has sp:where': function(t){ assert.ok(t["sp:where"]); }
, 'Graph:':
{ topic: function(t){return t.graphify();}
, 'Has index': function(graph){assert.isObject(graph.index); }
, 'Has _:query': function(graph){assert.isObject(graph.index['_:query']); }
, 'Has _:query / sp:where': function(graph){assert.isArray(graph.index['_:query']['sp:where']); }
, '_:query / sp:where':
{ topic: function(graph){ return {graph:graph, subject:graph.index['_:query']['sp:where'][0]}; }
, '...exists': function(t){ assert.isObject(t.graph.index[t.subject]); }
, 'Has /sp:path': function(t){ assert.isArray(t.graph.index[t.subject]['sp:path']); }
, 'Single /sp:path': function(t){ assert.strictEqual(t.graph.index[t.subject]['sp:path'].length, 1); }
, '/ sp:path':
{ topic: function(t){ return {graph:t.graph, subject:t.graph.index[t.subject]['sp:path'][0]}; }
, '...exists': function(t){ assert.isObject(t.graph.index[t.subject]); }
, 'Has /rdf:first': function(t){ assert.isArray(t.graph.index[t.subject]['rdf:first'.resolve()]); }
, 'Single /rdf:first': function(t){ assert.strictEqual(t.graph.index[t.subject]['rdf:first'.resolve()].length, 1); }
, '/rdf:first == "a"': function(t){ assert.strictEqual(t.graph.index[t.subject]['rdf:first'.resolve()][0], "a"); }
, 'Has /rdf:rest': function(t){ assert.isArray(t.graph.index[t.subject]['rdf:rest'.resolve()]); }
, 'Single /rdf:rest': function(t){ assert.strictEqual(t.graph.index[t.subject]['rdf:rest'.resolve()].length, 1); }
, '/rdf:rest == rdf:nil': function(t){ assert.strictEqual(t.graph.index[t.subject]['rdf:rest'.resolve()][0], "rdf:nil".resolve()); }
}
}
}
}
}).export(module);

0 comments on commit a974163

Please sign in to comment.