Permalink
Browse files

Updated tests

  • Loading branch information...
1 parent 2d4d2d5 commit f42a85c2785804da8a124b9b5764c7d708f01b51 @kriszyp committed Nov 30, 2010
Showing with 39 additions and 9 deletions.
  1. +37 −0 test/js-array.js
  2. +2 −9 {tests → test}/query.js
View
@@ -0,0 +1,37 @@
+var assert = require("assert"),
+ Query = require("../lib/query").Query,
+ executeQuery = require("../lib/js-array").executeQuery;
+
+var data = [
+ {
+ "with.dot": "dotted",
+ "nested": {
+ "property": "value"
+ },
+ "price": 10,
+ "name": "ten",
+ "tags": ["fun", "even"]
+ },
+ {
+ "price": 5,
+ "name": "five",
+ "tags": ["fun"]
+ }];
+
+exports.testFiltering = function() {
+ assert.equal(executeQuery("price=lt=10", {}, data).length, 1);
+ assert.equal(executeQuery("price=lt=11", {}, data).length, 2);
+ assert.equal(executeQuery("nested/property=value", {}, data).length, 1);
+ assert.equal(executeQuery("with.dot=dotted", {}, data).length, 1);
+ assert.equal(executeQuery("not(in(price,(5,10)))", {}, data).length, 0);
+ assert.equal(executeQuery("not(in(price,(5)))", {}, data).length, 1);
+ assert.equal(executeQuery("any(tags,even)", {}, data).length, 1);
+ assert.equal(executeQuery("any(tags,fun)", {}, data).length, 2);
+ assert.equal(executeQuery("all(tags,fun)", {}, data).length, 1);
+ assert.equal(executeQuery("all(tags,even)", {}, data).length, 0);
+ assert.equal(executeQuery("not(all(tags,even))", {}, data).length, 2);
+};
+
+
+if (require.main === module)
+ require("patr/runner").run(exports);
@@ -1,9 +1,7 @@
var assert = require("assert"),
Query = require("../lib/query").Query,
parseQuery = require("../lib/parser").parseQuery;
- executeQuery = require("../lib/js-array").executeQuery;
-
-Array.prototype.match = function(query, params){return executeQuery(query, params || [], this);};
+exports.testJSArray = require("./js-array");
exports.testBehavior = function() {
//assert.error(parseQuery(), "parseQuery requires a string");
@@ -22,6 +20,7 @@ var queryPairs = {
{"a(b,c)": {name:"and", args:[{name:"a", args:["b", "c"]}]}},
{"a((b),c)": {"name": "and", args:[{name:"a", args:[["b"], "c"]}]}},
{"a((b,c),d)": {name:"and", args:[{name:"a", args:[["b", "c"], "d"]}]}},
+ {"a(b/c,d)": {name:"and", args:[{name:"a", args:[["b", "c"], "d"]}]}},
{"a(b)&c(d(e))": {name:"and", args:[
{name:"a", args:["b"]},
{name:"c", args:[{name:"d", args:["e"]}]}
@@ -159,12 +158,6 @@ exports.testBindParameters = function() {
assert.deepEqual(parsed, {name: 'and', args: [{name: 'eq', args: ['id', 'a']}], cache: {id: 'a'}});
};
-exports.testExecution = function() {
- // TODO
- // nested props: https://github.com/kriszyp/rql/issues/#issue/15
- assert.deepEqual([{"path":[1,2,3]},{"path":[9,3,7]}].match("foo.cat=3"), []);
-};
-
exports.testStringification = function() {
// TODO
var parsed;

0 comments on commit f42a85c

Please sign in to comment.