implement @tschaub's suggestions for ieq and ineq

This commit is contained in:
Bart van den Eijnden
2013-07-22 14:11:29 +02:00
parent 875edc540e
commit 369d692a90
2 changed files with 50 additions and 14 deletions

View File

@@ -191,32 +191,30 @@ ol.expr.lib[ol.expr.functions.LIKE] = function(value, pattern, wildCard,
/** /**
* Case insensitive comparison for equality. * Case insensitive comparison for equality.
* @param {string} attribute Name of the attribute. * @param {*} first First value.
* @param {string} value Value to test for equality. * @param {*} second Second value.
* @this {ol.Feature} * @this {ol.Feature}
*/ */
ol.expr.lib[ol.expr.functions.IEQ] = function(attribute, value) { ol.expr.lib[ol.expr.functions.IEQ] = function(first, second) {
var attributeValue = this.get(attribute); if (goog.isString(first) && goog.isString(second)) {
if (goog.isString(value) && goog.isString(attributeValue)) { return first.toUpperCase() == second.toUpperCase();
return value.toUpperCase() == attributeValue.toUpperCase();
} else { } else {
return value == attributeValue; return first == second;
} }
}; };
/** /**
* Case insensitive comparison for non-equality. * Case insensitive comparison for non-equality.
* @param {string} attribute Name of the attribute. * @param {*} first First value.
* @param {string} value Value to test for non-equality. * @param {*} second Second value.
* @this {ol.Feature} * @this {ol.Feature}
*/ */
ol.expr.lib[ol.expr.functions.INEQ] = function(attribute, value) { ol.expr.lib[ol.expr.functions.INEQ] = function(first, second) {
var attributeValue = this.get(attribute); if (goog.isString(first) && goog.isString(second)) {
if (goog.isString(value) && goog.isString(attributeValue)) { return first.toUpperCase() != second.toUpperCase();
return value.toUpperCase() == attributeValue.toUpperCase();
} else { } else {
return value != attributeValue; return first != second;
} }
}; };

View File

@@ -788,6 +788,44 @@ describe('ol.expr.lib', function() {
}); });
describe('ieq()', function() {
var one = new ol.Feature({foo: 'Bar'});
var two = new ol.Feature({bar: 'Foo'});
var ieq1 = parse('ieq(foo, "bar")');
var ieq2 = parse('ieq("foo", bar)');
it('case-insensitive equality for an attribute', function() {
expect(evaluate(ieq1, one), true);
});
it('case-insensitive equality for an attribute as second argument',
function() {
expect(evaluate(ieq2, two), true);
});
});
describe('ineq()', function() {
var one = new ol.Feature({foo: 'Bar'});
var two = new ol.Feature({bar: 'Foo'});
var ieq1 = parse('ineq(foo, "bar")');
var ieq2 = parse('ineq("foo", bar)');
it('case-insensitive non-equality for an attribute', function() {
expect(evaluate(ieq1, one), false);
});
it('case-insensitive non-equality for an attribute as second argument',
function() {
expect(evaluate(ieq2, two), false);
});
});
}); });
describe('ol.expr.register()', function() { describe('ol.expr.register()', function() {