Skip to content
This repository has been archived by the owner on Nov 24, 2022. It is now read-only.

Commit

Permalink
fix for non-retrieval of zero values, most embarassing. fixes #20
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Glegg committed Jun 15, 2013
1 parent 02205a7 commit 833b2e2
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/SpahQL.js
Expand Up @@ -245,7 +245,7 @@ SpahQL = SpahQL_classExtend("SpahQL", Array, {
}
else {
results = (arguments.length > 1)? Array.prototype.slice.call(arguments) : results;
results = (results.value && typeof(results.value)!="function")? [results] : results;
results = (results.hasOwnProperty('value') && typeof(results.value)!="function")? [results] : results;
for(var i in results) this.push(results[i]);
}
},
Expand Down Expand Up @@ -374,7 +374,7 @@ SpahQL = SpahQL_classExtend("SpahQL", Array, {
var results = [];
this.each(function() {
SpahQL.select(query, this.sourceData(), this.value(), this.path()).each(function() {
results.push(this[0]);
results.push(this[0])
});
});
return new SpahQL(results);
Expand Down Expand Up @@ -838,8 +838,8 @@ SpahQL = SpahQL_classExtend("SpahQL", Array, {
"destroy": function(target, key) {
if(!target || typeof(target)!="object") {
key = target;
target = this[0];
}
target = this[0]
; }

if(target && key) {
// Key deletion
Expand Down
10 changes: 10 additions & 0 deletions test/SpahQL.QueryRunner.test.js
Expand Up @@ -47,6 +47,16 @@ exports["SpahQL.QueryRunner"] = {
}
test.done();
},

"Selection Queries: retrieves zero values": function(test) {
var q = qp.parseQuery("/hsh/zero");
var data = {hsh: {zero: 0, one: 1}};

test.deepEqual(qr.select(q, data),
[{path: "/hsh/zero", value: 0, sourceData: data}]
);
test.done();
},

// Run all assertion queries
"Assertion query fixtures: Runs the fixture set with the correct results": function(test) {
Expand Down
10 changes: 10 additions & 0 deletions test/SpahQL.Token.PathComponent.test.js
Expand Up @@ -86,6 +86,16 @@ exports["SpahQL.Token.PathComponent"] = {
test.done();
},

"Evaluates with an zero value": function(test) {
var token = SpahQL.Token.PathComponent.parseAt(0, "/zero")[1];
var data = {hsh: {zero: 0, one: 1}};

test.deepEqual(token.evaluate(data, data.hsh, "/hsh"),
[{path: "/hsh/zero", value: 0, sourceData: data}]
);
test.done();
},

"Evaluates with a named key and the recursive flag": function(test) {
var token = SpahQL.Token.PathComponent.parseAt(0, "//a")[1];
var data = {a: {a: "aa"}};
Expand Down
10 changes: 10 additions & 0 deletions test/SpahQL.Token.SelectionQuery.test.js
Expand Up @@ -18,6 +18,16 @@ exports["SpahQL.Token.SelectionQuery"] = {

test.equal(null, SpahQL.Token.SelectionQuery.parseAt(0, "0000"));
test.done();
},

"Correctly returns a zero value": function(test) {
var token = SpahQL.Token.SelectionQuery.parseAt(0, "/hsh/zero")[1];
var data = {hsh: {zero: 0, one: 1}};

test.deepEqual(token.evaluate(data, data, "/"),
[{path: "/hsh/zero", value: 0, sourceData: data}]
);
test.done();
}

};
12 changes: 12 additions & 0 deletions test/SpahQL.test.js
Expand Up @@ -256,6 +256,18 @@ exports["SpahQL"] = {
test.done();
},

"select() retrieves zero-value results": function(test) {
var data = {a: {zero: 0, one: 1}, b: {zero: 0, two: 2}};
var db = SpahQL.db(data);

var res = db.select("//zero");

test.equal(res.length, 2);
test.deepEqual(res.values(), [0,0]);

test.done();
},

"assert() passes if all results match the assertion": function(test) {
var data = {a: {aa: "aaval", ab: "abval", c: {inner: "accval"}}, b: {bb: "bbval", bc: "bcval", c: {inner: "bccval"}}}
var db = SpahQL.db(data);
Expand Down

0 comments on commit 833b2e2

Please sign in to comment.