Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('turns numbers into doubles', () => {
const xpathSequence = adaptJavaScriptValueToXPathValue(1.0, 'xs:double');
chai.assert(xpathSequence.isSingleton(), 'is a singleton sequence');
chai.assert(xpathSequence.first().type === 'xs:double', 'is a double');
chai.assert.equal(xpathSequence.first().value, 1.0, 'is 1.0');
});
it('turns numbers into integers', () => {
const xpathSequence = adaptJavaScriptValueToXPathValue(1, 'xs:integer');
chai.assert(xpathSequence.isSingleton(), 'is a singleton sequence');
chai.assert(xpathSequence.first().type === 'xs:integer', 'is an integer');
chai.assert.equal(xpathSequence.first().value, 1, 'is 1');
});
it('turns date into xs:gYearMonth', () => {
const xpathSequence = adaptJavaScriptValueToXPathValue(
new Date(Date.UTC(2018, 5, 22, 9, 10, 20)),
'xs:gYearMonth'
);
chai.assert(xpathSequence.isSingleton(), 'is a singleton sequence');
chai.assert(xpathSequence.first().type === 'xs:gYearMonth', 'is a gYearMonth');
chai.assert.deepEqual(
xpathSequence.first().value,
DateTime.fromString('2018-06Z'),
'is June 2018'
);
});
it('turns date into xs:time', () => {
const xpathSequence = adaptJavaScriptValueToXPathValue(
new Date(Date.UTC(2018, 5, 22, 9, 10, 20)),
'xs:time'
);
chai.assert(xpathSequence.isSingleton(), 'is a singleton sequence');
chai.assert(xpathSequence.first().type === 'xs:time', 'is a time');
chai.assert.deepEqual(
xpathSequence.first().value,
DateTime.fromString('09:10:20Z'),
'is 09:10:20'
);
});
it('turns nodes into nodes', () => {
const xpathSequence = adaptJavaScriptValueToXPathValue(new slimdom.Document());
chai.assert(xpathSequence.isSingleton(), 'is a singleton sequence');
chai.assert(xpathSequence.first().type === 'document()', 'is a document');
});
it('turns date into xs:gMonthDay', () => {
const xpathSequence = adaptJavaScriptValueToXPathValue(
new Date(Date.UTC(2018, 5, 22, 9, 10, 20)),
'xs:gMonthDay'
);
chai.assert(xpathSequence.isSingleton(), 'is a singleton sequence');
chai.assert(xpathSequence.first().type === 'xs:gMonthDay', 'is a gMonthDay');
chai.assert.deepEqual(
xpathSequence.first().value,
DateTime.fromString('-06-22Z'),
'is 22nd June'
);
});
it('turns strings into xs:string*', () => {
const xpathSequence = adaptJavaScriptValueToXPathValue(['a', 'b', 'c'], 'xs:string*');
chai.assert.equal(xpathSequence.tryGetLength().value, 3, 'is a sequence with length 3');
const values = xpathSequence.getAllValues();
chai.assert(xpathSequence.first().type === 'xs:string', 'first is a string');
chai.assert(values[1].type === 'xs:string', 'second is a string');
chai.assert(values[2].type === 'xs:string', 'third is a string');
chai.assert.equal(xpathSequence.first().value, 'a', 'is a');
chai.assert.equal(values[1].value, 'b', 'is b');
chai.assert.equal(values[2].value, 'c', 'is c');
});
it('can automatically convert booleans', () => {
const xpathSequence = adaptJavaScriptValueToXPathValue(true, 'item()');
chai.assert(xpathSequence.isSingleton(), 'is a singleton sequence');
chai.assert(xpathSequence.first().type === 'xs:boolean', 'is a boolean');
chai.assert.equal(xpathSequence.first().value, true, 'is true');
});
it('can automatically convert objects', () => {
const xpathSequence = adaptJavaScriptValueToXPathValue({}, 'item()');
chai.assert(xpathSequence.isSingleton(), 'is a singleton sequence');
chai.assert(xpathSequence.first().type === 'map(*)', 'is a map');
});
it('can automatically convert null to the empty sequence', () => {
const xpathSequence = adaptJavaScriptValueToXPathValue(null);
chai.assert(xpathSequence.isEmpty(), 'is the empty sequence');
});