make expression(a, b) resolve to a = b

This commit is contained in:
Kevin Anthoney 2016-08-06 00:09:28 +01:00
Родитель 24bdee55a9
Коммит 651897762e
3 изменённых файлов: 10 добавлений и 2 удалений

Просмотреть файл

@ -56,6 +56,10 @@ var Expression = function(field, op, value)
} else {
left = `${escape(field, true)}`;
}
if(value === undefined) {
value = op;
op = 'eq';
}
if(value instanceof Expression) {
right = `(${value.toString()})`;
} else {

Просмотреть файл

@ -32,6 +32,10 @@ describe('expression tests', function() {
expect(new Expression(e2, '=', e3).toString()).toEqual('(b add 2) eq (5)');
});
it('should express e2 = e3, method 2', function() {
expect(new Expression(e2, e3).toString()).toEqual('(b add 2) eq (5)');
});
it('should express e2 != e3', function() {
expect(new Expression(e2, '!=', e3).toString()).toEqual('(b add 2) ne (5)');
});

Просмотреть файл

@ -34,7 +34,7 @@ describe('filter tests', function() {
});
it('should produce a filter credit > 5000 and (balance = 0 or status = \'stop\')', function() {
expect(odata.filter('credit', '>', 5000).and(Odata.expression('balance', '=', 0).or('status', '=', 'stop')).query())
expect(odata.filter('credit', '>', 5000).and(Odata.expression('balance', 0).or('status', 'stop')).query())
.toEqual('https://example.com/Customer?%24filter=(credit%20gt%205000)%20and%20((balance%20eq%200)' +
'%20or%20(status%20eq%20\'stop\'))');
});
@ -45,7 +45,7 @@ describe('filter tests', function() {
});
it('should produce a filter \'ABC001\' eq account', function() {
expect(odata.filter(Odata.literal('ABC001'), '=', Odata.identifier('account')).query())
expect(odata.filter(Odata.literal('ABC001'), Odata.identifier('account')).query())
.toEqual('https://example.com/Customer?%24filter=\'ABC001\'%20eq%20account');
});