Skip to content

Commit 09dbff1

Browse files
committed
Clarify literals handling
1 parent 31bab3b commit 09dbff1

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

lib/query/woqlBuilder.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ WOQLQuery.prototype.boolean = function (tf) {
8686
};
8787

8888
/**
89-
* @param {any} s
90-
* @param {string} t
91-
* @returns {object}
89+
* @param {any} s - the value of the literal
90+
* @param {string} t - the type of the literal, e.g. 'xsd:string', 'xsd:boolean'
91+
* @returns {object} - a WOQL DataValue object with the given type and value
9292
*/
9393
WOQLQuery.prototype.literal = function (s, t) {
9494
t = t.indexOf(':') === -1 ? `xsd:${t}` : t;

test/woqlLiteral.spec.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const { expect } = require('chai');
2+
const WOQL = require('../lib/woql');
3+
4+
describe('WOQL.literal() tests', () => {
5+
it('should correctly wrap literal value 0 with xsd:double in DataValue structure', () => {
6+
const result = WOQL.eq("v:var", WOQL.literal(0, 'xsd:double'));
7+
8+
const expected = {
9+
'@type': 'Equals',
10+
'left': {
11+
'@type': 'Value',
12+
'variable': 'var'
13+
},
14+
'right': {
15+
'@type': 'Value',
16+
'data': {
17+
'@type': 'xsd:double',
18+
'@value': 0
19+
}
20+
}
21+
};
22+
23+
expect(result.query).to.eql(expected);
24+
});
25+
});

0 commit comments

Comments
 (0)