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

Commit bbcbcc7

Browse files
committed
Implement xsd:integer.
1 parent 9b94fe2 commit bbcbcc7

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/util/SparqlExpressionEvaluator.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var N3Util = require('n3').Util,
55

66
var XSD = 'http://www.w3.org/2001/XMLSchema#',
77
XSD_INTEGER = XSD + 'integer',
8+
XSD_DOUBLE = XSD + 'double',
89
XSD_BOOLEAN = XSD + 'boolean',
910
XSD_TRUE = '"true"^^' + XSD_BOOLEAN,
1011
XSD_FALSE = '"false"^^' + XSD_BOOLEAN;
@@ -145,6 +146,9 @@ operators = {
145146
'str': function (a) {
146147
return N3Util.isLiteral(a) ? a : '"' + a + '"';
147148
},
149+
'http://www.w3.org/2001/XMLSchema#integer': function (a) {
150+
return '"' + Math.floor(a) + '"^^http://www.w3.org/2001/XMLSchema#integer';
151+
},
148152
'http://www.w3.org/2001/XMLSchema#double': function (a) {
149153
a = a.toFixed();
150154
if (a.indexOf('.') < 0) a += '.0';
@@ -161,7 +165,7 @@ operators = {
161165
// TODO: Comparison operators can take simple literals and strings as well
162166
[
163167
'+', '-', '*', '/', '<', '<=', '>', '>=',
164-
'http://www.w3.org/2001/XMLSchema#double',
168+
XSD_INTEGER, XSD_DOUBLE,
165169
].forEach(function (operatorName) {
166170
operators[operatorName].type = 'numeric';
167171
});

test/util/SparqlExpressionEvaluator-test.js

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

414+
describe('of the xsd:integer operator', function () {
415+
var evaluator = SparqlExpressionEvaluator({
416+
type: 'operation',
417+
operator: 'http://www.w3.org/2001/XMLSchema#integer',
418+
args: ['"123.67"'],
419+
});
420+
421+
it('should return the literal as an integer', function () {
422+
evaluator({}).should.equal('"123"^^http://www.w3.org/2001/XMLSchema#integer');
423+
});
424+
});
425+
414426
describe('of the xsd:double operator', function () {
415427
var evaluator = SparqlExpressionEvaluator({
416428
type: 'operation',

0 commit comments

Comments
 (0)