Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Xiaowu Zhang
jio
Commits
1ebfd26d
Commit
1ebfd26d
authored
Jan 02, 2014
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
async key+query tests
parent
44a20b19
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
601 additions
and
493 deletions
+601
-493
test/queries/key-jiodate.tests.js
test/queries/key-jiodate.tests.js
+117
-79
test/queries/key-localstorage.tests.js
test/queries/key-localstorage.tests.js
+1
-49
test/queries/key-schema.tests.js
test/queries/key-schema.tests.js
+131
-99
test/queries/key.tests.js
test/queries/key.tests.js
+352
-266
No files found.
test/queries/key-jiodate.tests.js
View file @
1ebfd26d
/*jslint indent: 2, maxlen: 120, nomen: true, vars: true */
/*global define, exports, require, module, complex_queries, jiodate, window, test, ok,
equal, deepEqual, sinon */
equal, deepEqual, sinon
, start, stop, RSVP
*/
// define([module_name], [dependencies], module);
(
function
(
dependencies
,
module
)
{
...
...
@@ -17,8 +17,12 @@
module
(
'
Custom Key Queries with JIODate
'
);
var
noop
=
function
()
{
return
;
// use with RSVP.all
};
test
(
'
Stock comparison operators with year precision
'
,
function
()
{
var
doc
_list
,
doc
List
=
function
()
{
var
docList
=
function
()
{
return
[
{
'
identifier
'
:
'
twenty ten
'
,
'
date
'
:
'
2010-03-04T08:52:13.746Z
'
},
{
'
identifier
'
:
'
twenty eleven
'
,
'
date
'
:
'
2011-03-04T08:52:13.746Z
'
},
...
...
@@ -31,75 +35,101 @@
cast_to
:
jiodate
.
JIODate
}
}
},
query_list
=
null
;
doc_list
=
docList
();
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
'
date
'
,
value
:
'
2011
'
},
key_schema
).
exec
(
doc_list
);
deepEqual
(
doc_list
,
[
{
'
date
'
:
'
2011-03-04T08:52:13.746Z
'
,
'
identifier
'
:
'
twenty eleven
'
}
],
'
Match with "date = 2011" (query tree form)
'
);
doc_list
=
docList
();
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
'
date
'
,
operator
:
'
!=
'
,
value
:
'
2011
'
},
key_schema
).
exec
(
doc_list
);
deepEqual
(
doc_list
,
[
{
'
date
'
:
'
2010-03-04T08:52:13.746Z
'
,
'
identifier
'
:
'
twenty ten
'
},
{
'
date
'
:
'
2012-03-04T08:52:13.746Z
'
,
'
identifier
'
:
'
twenty twelve
'
}
],
'
Match with "date != 2011" (query tree form)
'
);
doc_list
=
docList
();
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
'
date
'
,
operator
:
'
<
'
,
value
:
'
2011
'
},
key_schema
).
exec
(
doc_list
);
deepEqual
(
doc_list
,
[
{
'
date
'
:
'
2010-03-04T08:52:13.746Z
'
,
'
identifier
'
:
'
twenty ten
'
}
],
'
Match with "date < 2011" (query tree form)
'
);
doc_list
=
docList
();
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
'
date
'
,
operator
:
'
<=
'
,
value
:
'
2011
'
},
key_schema
).
exec
(
doc_list
);
deepEqual
(
doc_list
,
[
{
'
date
'
:
'
2010-03-04T08:52:13.746Z
'
,
'
identifier
'
:
'
twenty ten
'
},
{
'
date
'
:
'
2011-03-04T08:52:13.746Z
'
,
'
identifier
'
:
'
twenty eleven
'
}
],
'
Match with "date <= 2011" (query tree form)
'
);
doc_list
=
docList
();
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
'
date
'
,
operator
:
'
>
'
,
value
:
'
2011
'
},
key_schema
).
exec
(
doc_list
);
deepEqual
(
doc_list
,
[
{
'
date
'
:
'
2012-03-04T08:52:13.746Z
'
,
'
identifier
'
:
'
twenty twelve
'
}
],
'
Match with "date > 2011" (query tree form)
'
);
doc_list
=
docList
();
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
'
date
'
,
operator
:
'
>=
'
,
value
:
'
2011
'
},
key_schema
).
exec
(
doc_list
);
deepEqual
(
doc_list
,
[
{
'
date
'
:
'
2011-03-04T08:52:13.746Z
'
,
'
identifier
'
:
'
twenty eleven
'
},
{
'
date
'
:
'
2012-03-04T08:52:13.746Z
'
,
'
identifier
'
:
'
twenty twelve
'
}
],
'
Match with "date >= 2011" (query tree form)
'
);
},
query_list
=
[],
promise
=
[];
stop
();
promise
.
push
(
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
'
date
'
,
value
:
'
2011
'
},
key_schema
).
exec
(
docList
()).
then
(
function
(
dl
)
{
deepEqual
(
dl
,
[
{
'
date
'
:
'
2011-03-04T08:52:13.746Z
'
,
'
identifier
'
:
'
twenty eleven
'
}
],
'
Match with "date = 2011" (query tree form)
'
);
})
);
promise
.
push
(
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
'
date
'
,
operator
:
'
!=
'
,
value
:
'
2011
'
},
key_schema
).
exec
(
docList
()).
then
(
function
(
dl
)
{
deepEqual
(
dl
,
[
{
'
date
'
:
'
2010-03-04T08:52:13.746Z
'
,
'
identifier
'
:
'
twenty ten
'
},
{
'
date
'
:
'
2012-03-04T08:52:13.746Z
'
,
'
identifier
'
:
'
twenty twelve
'
}
],
'
Match with "date != 2011" (query tree form)
'
);
})
);
promise
.
push
(
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
'
date
'
,
operator
:
'
<
'
,
value
:
'
2011
'
},
key_schema
).
exec
(
docList
()).
then
(
function
(
dl
)
{
deepEqual
(
dl
,
[
{
'
date
'
:
'
2010-03-04T08:52:13.746Z
'
,
'
identifier
'
:
'
twenty ten
'
}
],
'
Match with "date < 2011" (query tree form)
'
);
})
);
promise
.
push
(
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
'
date
'
,
operator
:
'
<=
'
,
value
:
'
2011
'
},
key_schema
).
exec
(
docList
()).
then
(
function
(
dl
)
{
deepEqual
(
dl
,
[
{
'
date
'
:
'
2010-03-04T08:52:13.746Z
'
,
'
identifier
'
:
'
twenty ten
'
},
{
'
date
'
:
'
2011-03-04T08:52:13.746Z
'
,
'
identifier
'
:
'
twenty eleven
'
}
],
'
Match with "date <= 2011" (query tree form)
'
);
})
);
promise
.
push
(
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
'
date
'
,
operator
:
'
>
'
,
value
:
'
2011
'
},
key_schema
).
exec
(
docList
()).
then
(
function
(
dl
)
{
deepEqual
(
dl
,
[
{
'
date
'
:
'
2012-03-04T08:52:13.746Z
'
,
'
identifier
'
:
'
twenty twelve
'
}
],
'
Match with "date > 2011" (query tree form)
'
);
})
);
promise
.
push
(
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
'
date
'
,
operator
:
'
>=
'
,
value
:
'
2011
'
},
key_schema
).
exec
(
docList
()).
then
(
function
(
dl
)
{
deepEqual
(
dl
,
[
{
'
date
'
:
'
2011-03-04T08:52:13.746Z
'
,
'
identifier
'
:
'
twenty eleven
'
},
{
'
date
'
:
'
2012-03-04T08:52:13.746Z
'
,
'
identifier
'
:
'
twenty twelve
'
}
],
'
Match with "date >= 2011" (query tree form)
'
);
})
);
query_list
=
[
[
...
...
@@ -119,9 +149,13 @@
query_list
.
forEach
(
function
(
o
)
{
var
qs
=
o
[
0
],
expected
=
o
[
1
];
doc_list
=
docList
();
complex_queries
.
QueryFactory
.
create
(
qs
,
key_schema
).
exec
(
doc_list
);
deepEqual
(
doc_list
,
expected
,
"
Match with '
"
+
qs
+
"
' (parsed query string)
"
);
promise
.
push
(
complex_queries
.
QueryFactory
.
create
(
qs
,
key_schema
).
exec
(
docList
()).
then
(
function
(
dl
)
{
deepEqual
(
dl
,
expected
,
"
Match with '
"
+
qs
+
"
' (parsed query string)
"
);
})
);
});
query_list
=
[
...
...
@@ -132,13 +166,17 @@
];
query_list
.
forEach
(
function
(
qs
)
{
doc_list
=
docList
();
complex_queries
.
QueryFactory
.
create
(
qs
,
key_schema
).
exec
(
doc_list
);
deepEqual
(
doc_list
,
[
],
"
Match with an invalid parsed string
"
+
qs
+
"
should return empty list but not raise errors
"
);
promise
.
push
(
complex_queries
.
QueryFactory
.
create
(
qs
,
key_schema
).
exec
(
docList
()).
then
(
function
(
dl
)
{
deepEqual
(
dl
,
[
],
"
Match with an invalid parsed string
"
+
qs
+
"
should return empty list but not raise errors
"
);
})
);
});
RSVP
.
all
(
promise
).
then
(
noop
).
always
(
start
);
});
}));
test/queries/key-localstorage.tests.js
View file @
1ebfd26d
...
...
@@ -21,54 +21,6 @@
local_storage
.
clear
();
/**
* all(promises): Promise
*
* Produces a promise that is resolved when all the given promises are
* fulfilled. The resolved value is an array of each of the answers of the
* given promises.
*
* @param {Array} promises The promises to use
* @return {Promise} A new promise
*/
function
all
(
promises
)
{
var
results
=
[],
i
,
count
=
0
;
function
cancel
()
{
var
j
;
for
(
j
=
0
;
j
<
promises
.
length
;
j
+=
1
)
{
if
(
typeof
promises
[
j
].
cancel
===
'
function
'
)
{
promises
[
j
].
cancel
();
}
}
}
return
new
RSVP
.
Promise
(
function
(
resolve
,
reject
,
notify
)
{
/*jslint unparam: true */
function
succeed
(
j
)
{
return
function
(
answer
)
{
results
[
j
]
=
answer
;
count
+=
1
;
if
(
count
!==
promises
.
length
)
{
return
;
}
resolve
(
results
);
};
}
function
notified
(
j
)
{
return
function
(
answer
)
{
notify
({
"
promise
"
:
promises
[
j
],
"
index
"
:
j
,
"
notified
"
:
answer
});
};
}
for
(
i
=
0
;
i
<
promises
.
length
;
i
+=
1
)
{
promises
[
i
].
then
(
succeed
(
i
),
succeed
(
i
),
notified
(
i
));
}
},
cancel
);
}
var
key_schema
=
{
cast_lookup
:
{
dateType
:
function
(
obj
)
{
...
...
@@ -105,7 +57,7 @@
o
.
date_b
=
new
Date
();
// put some document before listing them
all
([
RSVP
.
all
([
jio
.
put
({
"
_id
"
:
"
a
"
,
"
title
"
:
"
one
"
,
...
...
test/queries/key-schema.tests.js
View file @
1ebfd26d
/*jslint indent: 2, maxlen: 100, nomen: true, vars: true */
/*global define, exports, require, module, complex_queries, window, test, ok,
deepEqual, sinon */
deepEqual, sinon
, start, stop, RSVP
*/
// define([module_name], [dependencies], module);
(
function
(
dependencies
,
module
)
{
...
...
@@ -17,6 +17,10 @@
module
(
'
Custom Key Queries with Schema
'
);
var
noop
=
function
()
{
return
;
// use with RSVP.all
};
var
translationEqualityMatcher
=
function
(
data
)
{
return
function
(
object_value
,
value
)
{
value
=
data
[
value
];
...
...
@@ -24,7 +28,6 @@
};
};
/*jslint unparam: true*/
var
key_schema
=
{
cast_lookup
:
{
...
...
@@ -90,29 +93,37 @@
test
(
'
Keys defined in a Schema can be used like metadata
'
,
function
()
{
var
doc
_list
,
doc
List
=
function
()
{
var
docList
=
function
()
{
return
[
{
'
identifier
'
:
'
a
'
},
{
'
identifier
'
:
'
A
'
},
{
'
identifier
'
:
'
b
'
}
];
};
},
promise
=
[];
stop
();
promise
.
push
(
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
'
case_insensitive_identifier
'
,
value
:
'
A
'
},
key_schema
).
exec
(
docList
()).
then
(
function
(
dl
)
{
deepEqual
(
dl
,
[
{
'
identifier
'
:
'
a
'
},
{
'
identifier
'
:
'
A
'
}
],
'
Key Schema: case_insensitive_identifier
'
);
})
);
doc_list
=
docList
();
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
'
case_insensitive_identifier
'
,
value
:
'
A
'
},
key_schema
).
exec
(
doc_list
);
deepEqual
(
doc_list
,
[
{
'
identifier
'
:
'
a
'
},
{
'
identifier
'
:
'
A
'
}
],
'
Key Schema: case_insensitive_identifier
'
);
RSVP
.
all
(
promise
).
then
(
noop
).
always
(
start
);
});
test
(
'
Standard date keys
'
,
function
()
{
var
doc
_list
,
doc
List
=
function
()
{
var
docList
=
function
()
{
return
[
{
'
identifier
'
:
'
a
'
,
'
date
'
:
'
2013-01-01
'
},
{
'
identifier
'
:
'
b
'
,
'
date
'
:
'
2013-02-01
'
},
...
...
@@ -121,54 +132,58 @@
{
'
identifier
'
:
'
c
'
,
'
date
'
:
'
2013-03-03
'
},
{
'
identifier
'
:
'
d
'
,
'
date
'
:
'
2013-04-04
'
}
];
};
}
,
promise
=
[]
;
doc_list
=
docList
();
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
'
date_day
'
,
value
:
'
2013-02-02
'
},
key_schema
).
exec
(
doc_list
);
deepEqual
(
doc_list
,
[
{
'
identifier
'
:
'
bb
'
,
'
date
'
:
'
2013-02-02
'
}
],
'
Key Schema: same_day
'
);
doc_list
=
docList
();
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
'
date_month
'
,
value
:
'
2013-02-10
'
},
key_schema
).
exec
(
doc_list
);
deepEqual
(
doc_list
,
[
{
'
date
'
:
'
2013-02-01
'
,
'
identifier
'
:
'
b
'
},
{
'
date
'
:
'
2013-02-02
'
,
'
identifier
'
:
'
bb
'
},
{
'
date
'
:
'
2013-02-03
'
,
'
identifier
'
:
'
bbb
'
}
],
'
Key Schema: date_month
'
);
stop
();
promise
.
push
(
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
'
date_day
'
,
value
:
'
2013-02-02
'
},
key_schema
).
exec
(
docList
()).
then
(
function
(
dl
)
{
deepEqual
(
dl
,
[
{
'
identifier
'
:
'
bb
'
,
'
date
'
:
'
2013-02-02
'
}
],
'
Key Schema: same_day
'
);
})
);
promise
.
push
(
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
'
date_month
'
,
value
:
'
2013-02-10
'
},
key_schema
).
exec
(
docList
()).
then
(
function
(
dl
)
{
deepEqual
(
dl
,
[
{
'
date
'
:
'
2013-02-01
'
,
'
identifier
'
:
'
b
'
},
{
'
date
'
:
'
2013-02-02
'
,
'
identifier
'
:
'
bb
'
},
{
'
date
'
:
'
2013-02-03
'
,
'
identifier
'
:
'
bbb
'
}
],
'
Key Schema: date_month
'
);
})
);
doc_list
=
docList
();
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
'
date_year
'
,
value
:
'
2013-02-10
'
},
key_schema
).
exec
(
doc_list
);
deepEqual
(
doc_list
.
length
,
6
,
'
Key Schema: date_year
'
);
promise
.
push
(
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
'
date_year
'
,
value
:
'
2013-02-10
'
},
key_schema
).
exec
(
docList
()).
then
(
function
(
dl
)
{
deepEqual
(
dl
.
length
,
6
,
'
Key Schema: date_year
'
);
})
);
RSVP
.
all
(
promise
).
then
(
noop
).
always
(
start
);
});
test
(
'
Test key schema + complex queries
'
,
function
()
{
var
doc
_list
,
doc
List
=
function
()
{
var
docList
=
function
()
{
return
[
{
'
identifier
'
:
'
10
'
,
'
number
'
:
'
10
'
},
{
'
identifier
'
:
'
19
'
,
'
number
'
:
'
19
'
},
...
...
@@ -189,61 +204,77 @@
cast_to
:
'
intType
'
}
}
};
}
,
promise
=
[]
;
doc_list
=
docList
();
complex_queries
.
QueryFactory
.
create
({
type
:
'
complex
'
,
operator
:
'
OR
'
,
query_list
:
[{
type
:
'
simple
'
,
key
:
'
number
'
,
operator
:
'
<
'
,
value
:
'
19
'
},
{
type
:
'
simple
'
,
key
:
'
number
'
,
operator
:
'
=
'
,
value
:
'
19
'
}]
},
key_schema
).
exec
(
doc_list
);
deepEqual
(
doc_list
,
[
{
'
identifier
'
:
'
10
'
,
'
number
'
:
'
10
'
},
{
'
identifier
'
:
'
19
'
,
'
number
'
:
'
19
'
}
],
'
Key schema should be propagated from complex to simple queries
'
);
stop
();
promise
.
push
(
complex_queries
.
QueryFactory
.
create
({
type
:
'
complex
'
,
operator
:
'
OR
'
,
query_list
:
[{
type
:
'
simple
'
,
key
:
'
number
'
,
operator
:
'
<
'
,
value
:
'
19
'
},
{
type
:
'
simple
'
,
key
:
'
number
'
,
operator
:
'
=
'
,
value
:
'
19
'
}]
},
key_schema
).
exec
(
docList
()).
then
(
function
(
dl
)
{
deepEqual
(
dl
,
[
{
'
identifier
'
:
'
10
'
,
'
number
'
:
'
10
'
},
{
'
identifier
'
:
'
19
'
,
'
number
'
:
'
19
'
}
],
'
Key schema should be propagated from complex to simple queries
'
);
})
);
RSVP
.
all
(
promise
).
then
(
noop
).
always
(
start
);
});
test
(
'
Key Schema with translation lookup
'
,
function
()
{
var
doc
_list
,
doc
List
=
function
()
{
var
docList
=
function
()
{
return
[
{
'
identifier
'
:
'
1
'
,
'
state
'
:
'
open
'
},
{
'
identifier
'
:
'
2
'
,
'
state
'
:
'
closed
'
}
];
};
},
promise
=
[];
stop
();
promise
.
push
(
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
'
translated_state
'
,
value
:
'
ouvert
'
},
key_schema
).
exec
(
docList
()).
then
(
function
(
dl
)
{
deepEqual
(
dl
,
[
{
'
identifier
'
:
'
1
'
,
'
state
'
:
'
open
'
}
],
'
Key Schema: It should be possible to look for a translated string
'
);
})
);
doc_list
=
docList
();
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
'
translated_state
'
,
value
:
'
ouvert
'
},
key_schema
).
exec
(
doc_list
);
deepEqual
(
doc_list
,
[
{
'
identifier
'
:
'
1
'
,
'
state
'
:
'
open
'
}
],
'
Key Schema: It should be possible to look for a translated string
'
);
doc_list
=
docList
();
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
'
translated_state
'
,
operator
:
'
=
'
,
value
:
'
ouvert
'
},
key_schema
).
exec
(
doc_list
);
deepEqual
(
doc_list
,
[
{
'
identifier
'
:
'
1
'
,
'
state
'
:
'
open
'
}
],
'
Key Schema: It should be possible to look for a translated string with operator =
'
);
promise
.
push
(
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
'
translated_state
'
,
operator
:
'
=
'
,
value
:
'
ouvert
'
},
key_schema
).
exec
(
docList
()).
then
(
function
(
dl
)
{
deepEqual
(
dl
,
[
{
'
identifier
'
:
'
1
'
,
'
state
'
:
'
open
'
}
],
'
Key Schema: It should be possible to look for a translated string with operator =
'
);
})
);
// XXX not implemented yet
...
...
@@ -258,6 +289,7 @@
// {'identifier': '2', 'state': 'closed'}
// ], 'Key Schema: It should be possible to look for a translated string with operator !=');
RSVP
.
all
(
promise
).
then
(
noop
).
always
(
start
);
});
}));
test/queries/key.tests.js
View file @
1ebfd26d
/*jslint indent: 2, maxlen: 120, nomen: true, vars: true */
/*global define, exports, require, module, complex_queries, window, test, ok,
equal, deepEqual, sinon */
equal, deepEqual, sinon
, stop, start, RSVP
*/
// define([module_name], [dependencies], module);
(
function
(
dependencies
,
module
)
{
...
...
@@ -17,9 +17,13 @@
module
(
'
Custom Key Queries
'
);
var
noop
=
function
()
{
return
;
// use with RSVP.all
};
test
(
'
Simple Key with read_from
'
,
function
()
{
/*jslint unparam: true*/
var
doc
_list
,
doc
List
=
function
()
{
var
docList
=
function
()
{
return
[
{
'
identifier
'
:
'
a
'
},
{
'
identifier
'
:
'
A
'
},
...
...
@@ -35,29 +39,41 @@
return
(
object_value
.
toLowerCase
()
===
value
.
toLowerCase
());
}
}
};
}
,
promise
=
[]
;
/*jslint unparam: false*/
doc_list
=
docList
();
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
keys
.
title
,
value
:
'
a
'
}).
exec
(
doc_list
);
deepEqual
(
doc_list
,
[
{
'
identifier
'
:
'
a
'
}
],
'
It should be possible to query with an alias key
'
);
doc_list
=
docList
();
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
keys
.
case_insensitive_identifier
,
value
:
'
A
'
}).
exec
(
doc_list
);
deepEqual
(
doc_list
,
[
{
'
identifier
'
:
'
a
'
},
{
'
identifier
'
:
'
A
'
}
],
'
It should be possible to query with a case-insensitive alias key
'
);
stop
();
promise
.
push
(
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
keys
.
title
,
value
:
'
a
'
}).
exec
(
docList
()).
then
(
function
(
dl
)
{
deepEqual
(
dl
,
[
{
'
identifier
'
:
'
a
'
}
],
'
It should be possible to query with an alias key
'
);
})
);
promise
.
push
(
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
keys
.
case_insensitive_identifier
,
value
:
'
A
'
}).
exec
(
docList
()).
then
(
function
(
dl
)
{
deepEqual
(
dl
,
[
{
'
identifier
'
:
'
a
'
},
{
'
identifier
'
:
'
A
'
}
],
'
It should be possible to query with a case-insensitive alias key
'
);
})
);
RSVP
.
all
(
promise
).
then
(
noop
).
always
(
start
);
});
...
...
@@ -71,7 +87,7 @@
test
(
'
Simple Key with date casting
'
,
function
()
{
var
doc
_list
,
doc
List
=
function
()
{
var
docList
=
function
()
{
return
[
{
'
identifier
'
:
'
a
'
,
'
date
'
:
'
2013-01-01
'
},
{
'
identifier
'
:
'
b
'
,
'
date
'
:
'
2013-02-01
'
},
...
...
@@ -80,7 +96,7 @@
{
'
identifier
'
:
'
c
'
,
'
date
'
:
'
2013-03-03
'
},
{
'
identifier
'
:
'
d
'
,
'
date
'
:
'
2013-04-04
'
}
];
};
}
,
promise
=
[]
;
var
sameDay
=
function
(
a
,
b
)
{
return
(
...
...
@@ -119,53 +135,57 @@
}
};
doc_list
=
docList
();
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
keys
.
day
,
value
:
'
2013-02-02
'
}).
exec
(
doc_list
);
deepEqual
(
doc_list
,
[
{
'
identifier
'
:
'
bb
'
,
'
date
'
:
'
2013-02-02
'
}
],
'
It should be possible to compare dates with sameDay
'
);
doc_list
=
docList
();
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
keys
.
month
,
value
:
'
2013-02-10
'
}).
exec
(
doc_list
);
deepEqual
(
doc_list
,
[
{
'
date
'
:
'
2013-02-01
'
,
'
identifier
'
:
'
b
'
},
{
'
date
'
:
'
2013-02-02
'
,
'
identifier
'
:
'
bb
'
},
{
'
date
'
:
'
2013-02-03
'
,
'
identifier
'
:
'
bbb
'
}
],
'
It should be possible to compare dates with sameMonth
'
);
doc_list
=
docList
();
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
keys
.
year
,
value
:
'
2013-02-10
'
}).
exec
(
doc_list
);
deepEqual
(
doc_list
.
length
,
6
,
'
It should be possible to compare dates with sameYear
'
);
stop
();
promise
.
push
(
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
keys
.
day
,
value
:
'
2013-02-02
'
}).
exec
(
docList
()).
then
(
function
(
dl
)
{
deepEqual
(
dl
,
[
{
'
identifier
'
:
'
bb
'
,
'
date
'
:
'
2013-02-02
'
}
],
'
It should be possible to compare dates with sameDay
'
);
})
);
promise
.
push
(
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
keys
.
month
,
value
:
'
2013-02-10
'
}).
exec
(
docList
()).
then
(
function
(
dl
)
{
deepEqual
(
dl
,
[
{
'
date
'
:
'
2013-02-01
'
,
'
identifier
'
:
'
b
'
},
{
'
date
'
:
'
2013-02-02
'
,
'
identifier
'
:
'
bb
'
},
{
'
date
'
:
'
2013-02-03
'
,
'
identifier
'
:
'
bbb
'
}
],
'
It should be possible to compare dates with sameMonth
'
);
})
);
promise
.
push
(
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
keys
.
year
,
value
:
'
2013-02-10
'
}).
exec
(
docList
()).
then
(
function
(
dl
)
{
deepEqual
(
dl
.
length
,
6
,
'
It should be possible to compare dates with sameYear
'
);
})
);
RSVP
.
all
(
promise
).
then
(
noop
).
always
(
start
);
});
test
(
'
Simple Key with date casting and <=> operators
'
,
function
()
{
var
doc
_list
,
doc
List
=
function
()
{
var
docList
=
function
()
{
return
[
{
'
identifier
'
:
'
1
'
,
'
date
'
:
'
2013-01-01
'
},
{
'
identifier
'
:
'
2
'
,
'
date
'
:
'
2013-02-02
'
},
...
...
@@ -176,82 +196,109 @@
read_from
:
'
date
'
,
cast_to
:
dateCast
}
};
}
,
promise
=
[]
;
doc_list
=
docList
();
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
keys
.
mydate
,
operator
:
'
=
'
,
value
:
'
2013-02-02
'
}).
exec
(
doc_list
);
deepEqual
(
doc_list
,
[
{
'
identifier
'
:
'
2
'
,
'
date
'
:
'
2013-02-02
'
}
],
'
It should be possible to search for dates with operator =
'
);
doc_list
=
docList
();
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
keys
.
mydate
,
operator
:
'
!=
'
,
value
:
'
2013-02-02
'
}).
exec
(
doc_list
);
deepEqual
(
doc_list
,
[
{
'
identifier
'
:
'
1
'
,
'
date
'
:
'
2013-01-01
'
},
{
'
identifier
'
:
'
3
'
,
'
date
'
:
'
2013-03-03
'
}
],
'
It should be possible to search for dates with operator !=
'
);
doc_list
=
docList
();
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
keys
.
mydate
,
operator
:
'
<=
'
,
value
:
'
2013-02-02
'
}).
exec
(
doc_list
);
deepEqual
(
doc_list
,
[
{
'
identifier
'
:
'
1
'
,
'
date
'
:
'
2013-01-01
'
},
{
'
identifier
'
:
'
2
'
,
'
date
'
:
'
2013-02-02
'
}
],
'
It should be possible to search for dates with operator <=
'
);
doc_list
=
docList
();
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
keys
.
mydate
,
operator
:
'
<
'
,
value
:
'
2013-02-02
'
}).
exec
(
doc_list
);
deepEqual
(
doc_list
,
[
{
'
identifier
'
:
'
1
'
,
'
date
'
:
'
2013-01-01
'
}
],
'
It should be possible to search for dates with operator <
'
);
doc_list
=
docList
();
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
keys
.
mydate
,
operator
:
'
>
'
,
value
:
'
2013-02-02
'
}).
exec
(
doc_list
);
deepEqual
(
doc_list
,
[
{
'
identifier
'
:
'
3
'
,
'
date
'
:
'
2013-03-03
'
}
],
'
It should be possible to search for dates with operator >
'
);
doc_list
=
docList
();
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
keys
.
mydate
,
operator
:
'
>=
'
,
value
:
'
2013-02-02
'
}).
exec
(
doc_list
);
deepEqual
(
doc_list
,
[
{
'
identifier
'
:
'
2
'
,
'
date
'
:
'
2013-02-02
'
},
{
'
identifier
'
:
'
3
'
,
'
date
'
:
'
2013-03-03
'
}
],
'
It should be possible to search for dates with operator >=
'
);
stop
();
promise
.
push
(
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
keys
.
mydate
,
operator
:
'
=
'
,
value
:
'
2013-02-02
'
}).
exec
(
docList
()).
then
(
function
(
dl
)
{
deepEqual
(
dl
,
[
{
'
identifier
'
:
'
2
'
,
'
date
'
:
'
2013-02-02
'
}
],
'
It should be possible to search for dates with operator =
'
);
})
);
promise
.
push
(
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
keys
.
mydate
,
operator
:
'
!=
'
,
value
:
'
2013-02-02
'
}).
exec
(
docList
()).
then
(
function
(
dl
)
{
deepEqual
(
dl
,
[
{
'
identifier
'
:
'
1
'
,
'
date
'
:
'
2013-01-01
'
},
{
'
identifier
'
:
'
3
'
,
'
date
'
:
'
2013-03-03
'
}
],
'
It should be possible to search for dates with operator !=
'
);
})
);
promise
.
push
(
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
keys
.
mydate
,
operator
:
'
<=
'
,
value
:
'
2013-02-02
'
}).
exec
(
docList
()).
then
(
function
(
dl
)
{
deepEqual
(
dl
,
[
{
'
identifier
'
:
'
1
'
,
'
date
'
:
'
2013-01-01
'
},
{
'
identifier
'
:
'
2
'
,
'
date
'
:
'
2013-02-02
'
}
],
'
It should be possible to search for dates with operator <=
'
);
})
);
promise
.
push
(
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
keys
.
mydate
,
operator
:
'
<
'
,
value
:
'
2013-02-02
'
}).
exec
(
docList
()).
then
(
function
(
dl
)
{
deepEqual
(
dl
,
[
{
'
identifier
'
:
'
1
'
,
'
date
'
:
'
2013-01-01
'
}
],
'
It should be possible to search for dates with operator <
'
);
})
);
promise
.
push
(
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
keys
.
mydate
,
operator
:
'
>
'
,
value
:
'
2013-02-02
'
}).
exec
(
docList
()).
then
(
function
(
dl
)
{
deepEqual
(
dl
,
[
{
'
identifier
'
:
'
3
'
,
'
date
'
:
'
2013-03-03
'
}
],
'
It should be possible to search for dates with operator >
'
);
})
);
promise
.
push
(
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
keys
.
mydate
,
operator
:
'
>=
'
,
value
:
'
2013-02-02
'
}).
exec
(
docList
()).
then
(
function
(
dl
)
{
deepEqual
(
dl
,
[
{
'
identifier
'
:
'
2
'
,
'
date
'
:
'
2013-02-02
'
},
{
'
identifier
'
:
'
3
'
,
'
date
'
:
'
2013-03-03
'
}
],
'
It should be possible to search for dates with operator >=
'
);
})
);
RSVP
.
all
(
promise
).
then
(
noop
).
always
(
start
);
});
test
(
'
Simple Key with both equal_match and operator attributes
'
,
function
()
{
var
doc
_list
,
doc
List
=
function
()
{
var
docList
=
function
()
{
return
[
{
'
identifier
'
:
'
1
'
,
'
date
'
:
'
2013-01-01
'
},
{
'
identifier
'
:
'
2
'
,
'
date
'
:
'
2013-02-02
'
},
...
...
@@ -261,123 +308,148 @@
mydate
:
{
read_from
:
'
date
'
,
cast_to
:
dateCast
,
equal_match
:
function
alwaysTrue
()
{
return
true
;
}
equal_match
:
function
alwaysTrue
(
o1
)
{
/*, o2*/
return
o1
.
getDate
()
===
2
;
}
}
};
},
promise
=
[];
doc_list
=
docList
();
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
keys
.
mydate
,
value
:
'
2013-02-02
'
}).
exec
(
doc_list
);
deepEqual
(
doc_list
,
[
{
'
identifier
'
:
'
1
'
,
'
date
'
:
'
2013-01-01
'
},
{
'
identifier
'
:
'
2
'
,
'
date
'
:
'
2013-02-02
'
},
{
'
identifier
'
:
'
3
'
,
'
date
'
:
'
2013-03-03
'
}
],
'
It should be possible to use a catch-all filter
'
);
doc_list
=
docList
();
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
keys
.
mydate
,
operator
:
'
=
'
,
value
:
'
2013-02-02
'
}).
exec
(
doc_list
);
deepEqual
(
doc_list
,
[
{
'
identifier
'
:
'
1
'
,
'
date
'
:
'
2013-01-01
'
},
{
'
identifier
'
:
'
2
'
,
'
date
'
:
'
2013-02-02
'
},
{
'
identifier
'
:
'
3
'
,
'
date
'
:
'
2013-03-03
'
}
],
"
The catch-all filter overrides the default '=' operator
"
);
doc_list
=
docList
();
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
keys
.
mydate
,
operator
:
'
>=
'
,
value
:
'
2013-02-02
'
}).
exec
(
doc_list
);
deepEqual
(
doc_list
,
[
{
'
identifier
'
:
'
2
'
,
'
date
'
:
'
2013-02-02
'
},
{
'
identifier
'
:
'
3
'
,
'
date
'
:
'
2013-03-03
'
}
],
'
An explicit operator should override the catch-all filter
'
);
stop
();
promise
.
push
(
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
keys
.
mydate
,
value
:
'
2013-02-02
'
}).
exec
(
docList
()).
then
(
function
(
dl
)
{
deepEqual
(
dl
,
[
{
'
identifier
'
:
'
2
'
,
'
date
'
:
'
2013-02-02
'
}
],
"
'equal_match' with no 'operator'
"
);
})
);
promise
.
push
(
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
keys
.
mydate
,
operator
:
'
=
'
,
value
:
'
2013-01-01
'
}).
exec
(
docList
()).
then
(
function
(
dl
)
{
deepEqual
(
dl
,
[
{
'
identifier
'
:
'
2
'
,
'
date
'
:
'
2013-02-02
'
}
],
"
'equal_match' overrides '=' operator
"
);
})
);
promise
.
push
(
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
keys
.
mydate
,
operator
:
'
>=
'
,
value
:
'
2013-02-02
'
}).
exec
(
docList
()).
then
(
function
(
dl
)
{
deepEqual
(
dl
,
[
{
'
identifier
'
:
'
2
'
,
'
date
'
:
'
2013-02-02
'
},
{
'
identifier
'
:
'
3
'
,
'
date
'
:
'
2013-03-03
'
}
],
"
'equal_match' does not override '>' operator
"
);
})
);
RSVP
.
all
(
promise
).
then
(
noop
).
always
(
start
);
});
var
intType
=
function
(
value
)
{
if
(
typeof
value
===
'
string
'
)
{
return
parseInt
(
value
,
10
);
}
return
value
;
};
test
(
'
Test overriding operators and compound query
'
,
function
()
{
var
doc
_list
,
doc
List
=
function
()
{
var
docList
=
function
()
{
return
[
{
'
identifier
'
:
'
10
'
,
'
number
'
:
'
10
'
},
{
'
identifier
'
:
'
19
'
,
'
number
'
:
'
19
'
},
{
'
identifier
'
:
'
100
'
,
'
number
'
:
'
100
'
}
];
};
},
intType
=
function
(
value
)
{
if
(
typeof
value
===
'
string
'
)
{
return
parseInt
(
value
,
10
);
}
return
value
;
},
promise
=
[];
doc_list
=
docList
();
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
{
read_from
:
'
number
'
,
cast_to
:
intType
},
operator
:
'
>
'
,
value
:
'
19
'
}).
exec
(
doc_list
);
deepEqual
(
doc_list
,
[
{
'
identifier
'
:
'
100
'
,
'
number
'
:
'
100
'
}
],
'
Numbers are correctly compared (>) after casting
'
);
doc_list
=
docList
();
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
{
read_from
:
'
number
'
,
cast_to
:
intType
},
operator
:
'
<
'
,
value
:
'
19
'
}).
exec
(
doc_list
);
deepEqual
(
doc_list
,
[
{
'
identifier
'
:
'
10
'
,
'
number
'
:
'
10
'
}
],
'
Numbers are correctly compared (<) after casting
'
);
doc_list
=
docList
();
complex_queries
.
QueryFactory
.
create
({
type
:
'
complex
'
,
operator
:
'
OR
'
,
query_list
:
[{
stop
();
promise
.
push
(
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
{
read_from
:
'
number
'
,
cast_to
:
intType
},
operator
:
'
<
'
,
operator
:
'
>
'
,
value
:
'
19
'
},
{
}).
exec
(
docList
()).
then
(
function
(
dl
)
{
deepEqual
(
dl
,
[
{
'
identifier
'
:
'
100
'
,
'
number
'
:
'
100
'
}
],
'
Numbers are correctly compared (>) after casting
'
);
})
);
promise
.
push
(
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
{
read_from
:
'
number
'
,
cast_to
:
intType
},
operator
:
'
=
'
,
operator
:
'
<
'
,
value
:
'
19
'
}]
}).
exec
(
doc_list
);
deepEqual
(
doc_list
,
[
{
'
identifier
'
:
'
10
'
,
'
number
'
:
'
10
'
},
{
'
identifier
'
:
'
19
'
,
'
number
'
:
'
19
'
}
],
'
Custom keys should also work within compound queries
'
);
}).
exec
(
docList
()).
then
(
function
(
dl
)
{
deepEqual
(
dl
,
[
{
'
identifier
'
:
'
10
'
,
'
number
'
:
'
10
'
}
],
'
Numbers are correctly compared (<) after casting
'
);
})
);
promise
.
push
(
complex_queries
.
QueryFactory
.
create
({
type
:
'
complex
'
,
operator
:
'
OR
'
,
query_list
:
[{
type
:
'
simple
'
,
key
:
{
read_from
:
'
number
'
,
cast_to
:
intType
},
operator
:
'
<
'
,
value
:
'
19
'
},
{
type
:
'
simple
'
,
key
:
{
read_from
:
'
number
'
,
cast_to
:
intType
},
operator
:
'
=
'
,
value
:
'
19
'
}]
}).
exec
(
docList
()).
then
(
function
(
dl
)
{
deepEqual
(
dl
,
[
{
'
identifier
'
:
'
10
'
,
'
number
'
:
'
10
'
},
{
'
identifier
'
:
'
19
'
,
'
number
'
:
'
19
'
}
],
'
Custom keys should also work within compound queries
'
);
})
);
RSVP
.
all
(
promise
).
then
(
noop
).
always
(
start
);
});
...
...
@@ -390,7 +462,7 @@
test
(
'
Simple Key with translation lookup
'
,
function
()
{
var
doc
_list
,
doc
List
=
function
()
{
var
docList
=
function
()
{
return
[
{
'
identifier
'
:
'
1
'
,
'
state
'
:
'
open
'
},
{
'
identifier
'
:
'
2
'
,
'
state
'
:
'
closed
'
}
...
...
@@ -402,31 +474,39 @@
read_from
:
'
state
'
,
equal_match
:
equalState
}
};
},
promise
=
[];
doc_list
=
docList
();
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
keys
.
translated_state
,
value
:
'
ouvert
'
}).
exec
(
doc_list
);
deepEqual
(
doc_list
,
[
{
'
identifier
'
:
'
1
'
,
'
state
'
:
'
open
'
}
],
'
It should be possible to look for a translated string with a custom match function
'
);
doc_list
=
docList
();
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
keys
.
translated_state
,
operator
:
'
=
'
,
value
:
'
ouvert
'
}).
exec
(
doc_list
);
deepEqual
(
doc_list
,
[
{
'
identifier
'
:
'
1
'
,
'
state
'
:
'
open
'
}
],
'
It should be possible to look for a translated string with operator =
'
);
stop
();
promise
.
push
(
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
keys
.
translated_state
,
value
:
'
ouvert
'
}).
exec
(
docList
()).
then
(
function
(
dl
)
{
deepEqual
(
dl
,
[
{
'
identifier
'
:
'
1
'
,
'
state
'
:
'
open
'
}
],
'
It should be possible to look for a translated string with a custom match function
'
);
})
);
promise
.
push
(
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
keys
.
translated_state
,
operator
:
'
=
'
,
value
:
'
ouvert
'
}).
exec
(
docList
()).
then
(
function
(
dl
)
{
deepEqual
(
dl
,
[
{
'
identifier
'
:
'
1
'
,
'
state
'
:
'
open
'
}
],
'
It should be possible to look for a translated string with operator =
'
);
})
);
// XXX not implemented yet
// doc_list = docList();
...
...
@@ -440,7 +520,7 @@
// {'identifier': '2', 'state': 'closed'}
// ], 'It should be possible to look for a translated string with operator !=');
RSVP
.
all
(
promise
).
then
(
noop
).
always
(
start
);
});
...
...
@@ -483,7 +563,7 @@
test
(
'
Query with accent folding and wildcard
'
,
function
()
{
/*jslint unparam: true*/
var
doc
_list
,
doc
List
=
function
()
{
var
docList
=
function
()
{
return
[
{
'
identifier
'
:
'
àéîöùç
'
},
{
'
identifier
'
:
'
âèî ôùc
'
},
...
...
@@ -495,21 +575,27 @@
read_from
:
'
identifier
'
,
cast_to
:
accentFold
}
};
}
,
promise
=
[]
;
/*jslint unparam: false*/
doc_list
=
docList
();
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
keys
.
identifier
,
value
:
'
aei%
'
}).
exec
(
doc_list
);
deepEqual
(
doc_list
,
[
{
'
identifier
'
:
'
àéîöùç
'
},
{
'
identifier
'
:
'
âèî ôùc
'
}
],
'
It should be possible to query regardless of accents
'
);
stop
();
promise
.
push
(
complex_queries
.
QueryFactory
.
create
({
type
:
'
simple
'
,
key
:
keys
.
identifier
,
value
:
'
aei%
'
}).
exec
(
docList
()).
then
(
function
(
dl
)
{
deepEqual
(
dl
,
[
{
'
identifier
'
:
'
àéîöùç
'
},
{
'
identifier
'
:
'
âèî ôùc
'
}
],
'
It should be possible to query regardless of accents
'
);
})
);
RSVP
.
all
(
promise
).
then
(
noop
).
always
(
start
);
});
}));
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment