Allow Filter to accept non-tuple-based terms.

We make this happen inside of canonicalize_term.

(imported from commit 0571f6cac8ffdc806af56423cc98134c7493139e)
This commit is contained in:
Steve Howell
2014-02-03 13:20:50 -05:00
parent 112bc5ceda
commit 89ea079dce
2 changed files with 15 additions and 3 deletions

View File

@@ -145,9 +145,10 @@ Filter.canonicalize_operator = function (operator) {
} }
}; };
Filter.canonicalize_term = function (tuple) { Filter.canonicalize_term = function (opts) {
var operator = tuple[0]; // Legacy code may still call use with a tuple of [operator, operand].
var operand = tuple[1]; var operator = opts.operator || opts[0];
var operand = opts.operand || opts[1];
operator = Filter.canonicalize_operator(operator); operator = Filter.canonicalize_operator(operator);

View File

@@ -42,6 +42,17 @@ function assert_result_matches_legacy_terms(result, terms) {
assert(! filter.can_apply_locally()); assert(! filter.can_apply_locally());
}()); }());
(function test_new_style_operators() {
var term = {
operator: 'stream',
operand: 'foo'
};
var operators = [term];
var filter = new Filter(operators);
assert.deepEqual(filter.operands('stream'), ['foo']);
}());
(function test_public_operators() { (function test_public_operators() {
var operators = [['stream', 'foo'], ['topic', 'bar']]; var operators = [['stream', 'foo'], ['topic', 'bar']];
var filter = new Filter(operators); var filter = new Filter(operators);