Skip to content
This repository was archived by the owner on Feb 5, 2020. It is now read-only.

Commit 01e1af5

Browse files
committed
SPARQL.js uses functionCall for functions.
1 parent bbcbcc7 commit 01e1af5

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

lib/util/SparqlExpressionEvaluator.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ evaluators = {
5353
// Evaluates an operation
5454
operation: function (expression) {
5555
// Find the operator and check the number of arguments matches the expression
56-
var operatorName = expression.operator, operator = operators[operatorName];
56+
var operatorName = expression.operator || expression.function,
57+
operator = operators[operatorName];
5758
if (!operator)
5859
throw new UnsupportedOperatorError(operatorName);
5960
if (operator.length !== expression.args.length)
@@ -111,6 +112,7 @@ evaluators = {
111112
})(operator, argumentExpressions);
112113
},
113114
};
115+
evaluators.functionCall = evaluators.operation;
114116

115117
// Operators for each of the operator types
116118
operators = {
@@ -202,12 +204,12 @@ UnsupportedExpressionError = createErrorType('UnsupportedExpressionError', funct
202204
});
203205

204206
UnsupportedOperatorError = createErrorType('UnsupportedExpressionError', function (operatorName) {
205-
this.message = 'Unsupported operator: ' + operatorName.toUpperCase() + '.';
207+
this.message = 'Unsupported operator: ' + operatorName + '.';
206208
});
207209

208210
InvalidArgumentsNumberError = createErrorType('InvalidArgumentsNumberError',
209211
function (operatorName, actualNumber, expectedNumber) {
210-
this.message = 'Invalid number of arguments for ' + operatorName.toUpperCase() + ': ' +
212+
this.message = 'Invalid number of arguments for ' + operatorName + ': ' +
211213
actualNumber + ' (expected: ' + expectedNumber + ').';
212214
});
213215

test/util/SparqlExpressionEvaluator-test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -411,9 +411,9 @@ describe('SparqlExpressionEvaluator', function () {
411411
});
412412
});
413413

414-
describe('of the xsd:integer operator', function () {
414+
describe('of the xsd:integer function', function () {
415415
var evaluator = SparqlExpressionEvaluator({
416-
type: 'operation',
416+
type: 'functionCall',
417417
operator: 'http://www.w3.org/2001/XMLSchema#integer',
418418
args: ['"123.67"'],
419419
});
@@ -423,9 +423,9 @@ describe('SparqlExpressionEvaluator', function () {
423423
});
424424
});
425425

426-
describe('of the xsd:double operator', function () {
426+
describe('of the xsd:double function', function () {
427427
var evaluator = SparqlExpressionEvaluator({
428-
type: 'operation',
428+
type: 'functionCall',
429429
operator: 'http://www.w3.org/2001/XMLSchema#double',
430430
args: ['"123"'],
431431
});
@@ -471,14 +471,14 @@ describe('SparqlExpressionEvaluator', function () {
471471
describe('of an unsupported operator', function () {
472472
it('should throw an error', function () {
473473
(function () { SparqlExpressionEvaluator({ type: 'operation', operator: 'invalid' }); })
474-
.should.throw('Unsupported operator: INVALID.');
474+
.should.throw('Unsupported operator: invalid.');
475475
});
476476
});
477477

478478
describe('of an operator with an incorrect number of arguments', function () {
479479
it('should throw an error', function () {
480480
(function () { SparqlExpressionEvaluator({ type: 'operation', operator: 'regex', args: [1] }); })
481-
.should.throw('Invalid number of arguments for REGEX: 1 (expected: 2).');
481+
.should.throw('Invalid number of arguments for regex: 1 (expected: 2).');
482482
});
483483
});
484484

0 commit comments

Comments
 (0)