Commit de9e2e19 authored by Tristan Cavelier's avatar Tristan Cavelier

simplequery.js updated to pass tests

parent 55a305d5
...@@ -1238,10 +1238,33 @@ SimpleQuery.prototype.serialized = function () { ...@@ -1238,10 +1238,33 @@ SimpleQuery.prototype.serialized = function () {
*/ */
SimpleQuery.prototype["="] = function (object_value, comparison_value, SimpleQuery.prototype["="] = function (object_value, comparison_value,
wildcard_character) { wildcard_character) {
return convertStringToRegExp( var value, i;
if (!Array.isArray(object_value)) {
object_value = [object_value];
}
for (i = 0; i < object_value.length; i += 1) {
value = object_value[i];
if (typeof value === 'object') {
value = value.content;
}
if (comparison_value === undefined) {
if (value === undefined) {
return true;
} else {
return false;
}
}
if (value === undefined) {
return false;
}
if (convertStringToRegExp(
comparison_value.toString(), comparison_value.toString(),
wildcard_character || "%" wildcard_character
).test(object_value.toString()); ).test(value.toString())) {
return true;
}
}
return false;
}; };
/** /**
...@@ -1255,10 +1278,33 @@ SimpleQuery.prototype["="] = function (object_value, comparison_value, ...@@ -1255,10 +1278,33 @@ SimpleQuery.prototype["="] = function (object_value, comparison_value,
*/ */
SimpleQuery.prototype["!="] = function (object_value, comparison_value, SimpleQuery.prototype["!="] = function (object_value, comparison_value,
wildcard_character) { wildcard_character) {
return !convertStringToRegExp( var value, i;
if (!Array.isArray(object_value)) {
object_value = [object_value];
}
for (i = 0; i < object_value.length; i += 1) {
value = object_value[i];
if (typeof value === 'object') {
value = value.content;
}
if (comparison_value === undefined) {
if (value === undefined) {
return false;
} else {
return true;
}
}
if (value === undefined) {
return true;
}
if (convertStringToRegExp(
comparison_value.toString(), comparison_value.toString(),
wildcard_character || "%" wildcard_character
).test(object_value.toString()); ).test(value.toString())) {
return false;
}
}
return true;
}; };
/** /**
...@@ -1270,7 +1316,15 @@ SimpleQuery.prototype["!="] = function (object_value, comparison_value, ...@@ -1270,7 +1316,15 @@ SimpleQuery.prototype["!="] = function (object_value, comparison_value,
* @return {Boolean} true if lower, false otherwise * @return {Boolean} true if lower, false otherwise
*/ */
SimpleQuery.prototype["<"] = function (object_value, comparison_value) { SimpleQuery.prototype["<"] = function (object_value, comparison_value) {
return object_value < comparison_value; var value;
if (!Array.isArray(object_value)) {
object_value = [object_value];
}
value = object_value[0];
if (typeof value === 'object') {
value = value.content;
}
return value < comparison_value;
}; };
/** /**
...@@ -1283,7 +1337,15 @@ SimpleQuery.prototype["<"] = function (object_value, comparison_value) { ...@@ -1283,7 +1337,15 @@ SimpleQuery.prototype["<"] = function (object_value, comparison_value) {
* @return {Boolean} true if equal or lower, false otherwise * @return {Boolean} true if equal or lower, false otherwise
*/ */
SimpleQuery.prototype["<="] = function (object_value, comparison_value) { SimpleQuery.prototype["<="] = function (object_value, comparison_value) {
return object_value <= comparison_value; var value;
if (!Array.isArray(object_value)) {
object_value = [object_value];
}
value = object_value[0];
if (typeof value === 'object') {
value = value.content;
}
return value <= comparison_value;
}; };
/** /**
...@@ -1296,7 +1358,15 @@ SimpleQuery.prototype["<="] = function (object_value, comparison_value) { ...@@ -1296,7 +1358,15 @@ SimpleQuery.prototype["<="] = function (object_value, comparison_value) {
* @return {Boolean} true if greater, false otherwise * @return {Boolean} true if greater, false otherwise
*/ */
SimpleQuery.prototype[">"] = function (object_value, comparison_value) { SimpleQuery.prototype[">"] = function (object_value, comparison_value) {
return object_value > comparison_value; var value;
if (!Array.isArray(object_value)) {
object_value = [object_value];
}
value = object_value[0];
if (typeof value === 'object') {
value = value.content;
}
return value > comparison_value;
}; };
/** /**
...@@ -1309,7 +1379,15 @@ SimpleQuery.prototype[">"] = function (object_value, comparison_value) { ...@@ -1309,7 +1379,15 @@ SimpleQuery.prototype[">"] = function (object_value, comparison_value) {
* @return {Boolean} true if equal or greater, false otherwise * @return {Boolean} true if equal or greater, false otherwise
*/ */
SimpleQuery.prototype[">="] = function (object_value, comparison_value) { SimpleQuery.prototype[">="] = function (object_value, comparison_value) {
return object_value >= comparison_value; var value;
if (!Array.isArray(object_value)) {
object_value = [object_value];
}
value = object_value[0];
if (typeof value === 'object') {
value = value.content;
}
return value >= comparison_value;
}; };
query_class_dict.simple = SimpleQuery; query_class_dict.simple = SimpleQuery;
......
...@@ -82,10 +82,33 @@ SimpleQuery.prototype.serialized = function () { ...@@ -82,10 +82,33 @@ SimpleQuery.prototype.serialized = function () {
*/ */
SimpleQuery.prototype["="] = function (object_value, comparison_value, SimpleQuery.prototype["="] = function (object_value, comparison_value,
wildcard_character) { wildcard_character) {
return convertStringToRegExp( var value, i;
if (!Array.isArray(object_value)) {
object_value = [object_value];
}
for (i = 0; i < object_value.length; i += 1) {
value = object_value[i];
if (typeof value === 'object') {
value = value.content;
}
if (comparison_value === undefined) {
if (value === undefined) {
return true;
} else {
return false;
}
}
if (value === undefined) {
return false;
}
if (convertStringToRegExp(
comparison_value.toString(), comparison_value.toString(),
wildcard_character || "%" wildcard_character
).test(object_value.toString()); ).test(value.toString())) {
return true;
}
}
return false;
}; };
/** /**
...@@ -99,10 +122,33 @@ SimpleQuery.prototype["="] = function (object_value, comparison_value, ...@@ -99,10 +122,33 @@ SimpleQuery.prototype["="] = function (object_value, comparison_value,
*/ */
SimpleQuery.prototype["!="] = function (object_value, comparison_value, SimpleQuery.prototype["!="] = function (object_value, comparison_value,
wildcard_character) { wildcard_character) {
return !convertStringToRegExp( var value, i;
if (!Array.isArray(object_value)) {
object_value = [object_value];
}
for (i = 0; i < object_value.length; i += 1) {
value = object_value[i];
if (typeof value === 'object') {
value = value.content;
}
if (comparison_value === undefined) {
if (value === undefined) {
return false;
} else {
return true;
}
}
if (value === undefined) {
return true;
}
if (convertStringToRegExp(
comparison_value.toString(), comparison_value.toString(),
wildcard_character || "%" wildcard_character
).test(object_value.toString()); ).test(value.toString())) {
return false;
}
}
return true;
}; };
/** /**
...@@ -114,7 +160,15 @@ SimpleQuery.prototype["!="] = function (object_value, comparison_value, ...@@ -114,7 +160,15 @@ SimpleQuery.prototype["!="] = function (object_value, comparison_value,
* @return {Boolean} true if lower, false otherwise * @return {Boolean} true if lower, false otherwise
*/ */
SimpleQuery.prototype["<"] = function (object_value, comparison_value) { SimpleQuery.prototype["<"] = function (object_value, comparison_value) {
return object_value < comparison_value; var value;
if (!Array.isArray(object_value)) {
object_value = [object_value];
}
value = object_value[0];
if (typeof value === 'object') {
value = value.content;
}
return value < comparison_value;
}; };
/** /**
...@@ -127,7 +181,15 @@ SimpleQuery.prototype["<"] = function (object_value, comparison_value) { ...@@ -127,7 +181,15 @@ SimpleQuery.prototype["<"] = function (object_value, comparison_value) {
* @return {Boolean} true if equal or lower, false otherwise * @return {Boolean} true if equal or lower, false otherwise
*/ */
SimpleQuery.prototype["<="] = function (object_value, comparison_value) { SimpleQuery.prototype["<="] = function (object_value, comparison_value) {
return object_value <= comparison_value; var value;
if (!Array.isArray(object_value)) {
object_value = [object_value];
}
value = object_value[0];
if (typeof value === 'object') {
value = value.content;
}
return value <= comparison_value;
}; };
/** /**
...@@ -140,7 +202,15 @@ SimpleQuery.prototype["<="] = function (object_value, comparison_value) { ...@@ -140,7 +202,15 @@ SimpleQuery.prototype["<="] = function (object_value, comparison_value) {
* @return {Boolean} true if greater, false otherwise * @return {Boolean} true if greater, false otherwise
*/ */
SimpleQuery.prototype[">"] = function (object_value, comparison_value) { SimpleQuery.prototype[">"] = function (object_value, comparison_value) {
return object_value > comparison_value; var value;
if (!Array.isArray(object_value)) {
object_value = [object_value];
}
value = object_value[0];
if (typeof value === 'object') {
value = value.content;
}
return value > comparison_value;
}; };
/** /**
...@@ -153,7 +223,15 @@ SimpleQuery.prototype[">"] = function (object_value, comparison_value) { ...@@ -153,7 +223,15 @@ SimpleQuery.prototype[">"] = function (object_value, comparison_value) {
* @return {Boolean} true if equal or greater, false otherwise * @return {Boolean} true if equal or greater, false otherwise
*/ */
SimpleQuery.prototype[">="] = function (object_value, comparison_value) { SimpleQuery.prototype[">="] = function (object_value, comparison_value) {
return object_value >= comparison_value; var value;
if (!Array.isArray(object_value)) {
object_value = [object_value];
}
value = object_value[0];
if (typeof value === 'object') {
value = value.content;
}
return value >= comparison_value;
}; };
query_class_dict.simple = SimpleQuery; query_class_dict.simple = SimpleQuery;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment