Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('Passes xs:gDay as a javascript date', () => {
evaluateXPath('test:custom-gDay-param-function(xs:gDay("---29"))');
});
});
it('Can declare a function in a module and use the module from an XPath', () => {
registerXQueryModule(`
module namespace test = "https://www.example.org/test1";
declare %public function test:hello($a) {
"Hello " || $a
};
`);
const result = evaluateXPath(
'test:hello("World")',
null,
null,
null,
null,
{
moduleImports: {
test: 'https://www.example.org/test1'
}
});
chai.assert.equal(result, 'Hello World');
});
it('can run XPath expressions asynchronously', async () => {
const items = [];
const it = evaluateXPath('fontoxpath:sleep((), 10)', null, null, null, evaluateXPath.ASYNC_ITERATOR_TYPE);
for (let value = await it.next(); !value.done; value = await it.next()) {
items.push(value.value);
}
chai.assert(items.length === 0);
});
it('can resolve async results', async () => {
const items = [];
const it = evaluateXPath('fontoxpath:sleep(true(), 10)', null, null, null, evaluateXPath.ASYNC_ITERATOR_TYPE);
for (let value = await it.next(); !value.done; value = await it.next()) {
items.push(value.value);
}
chai.assert(items.length === 1);
chai.assert(items[0] === true);
});
it('Passes xs:gYear as a javascript date', () => {
evaluateXPath('test:custom-gYear-param-function(xs:gYear("2019"))');
});
it('Passes xs:gMonthDay as a javascript date', () => {
it('Can evaluate intermediately updating expressions', () =>
chai.assert.equal(
evaluateXPath(
'copy $ele := <element> modify insert node text{"test"} into $ele return $ele',
documentNode,
domFacade,
null,
evaluateXPath.FIRST_NODE_TYPE,
{ language: evaluateXPath.XQUERY_UPDATE_3_1_LANGUAGE }
).outerHTML,
'<element>test</element>'
));
</element>
registerXQueryModule(`
module namespace test = "https://www.example.org/test3/submodule";
declare %public function test:hello ($a) {
"Hello " || $a
};
`);
registerXQueryModule(`
module namespace test = "https://www.example.org/test3/mainModule";
import module namespace submodule = "https://www.example.org/test3/submodule";
declare %public function test:hello ($a) {
submodule:hello($a) || "!!!"
};
`);
const result = evaluateXPath('test:hello("World")', null, null, null, null, {
moduleImports: {
test: 'https://www.example.org/test3/mainModule'
}
});
chai.assert.equal(result, 'Hello World!!!');
});
() => evaluateXPath('fontoxpath:sleep(())', documentNode, domFacade),
'can not be resolved synchronously'
() =>
evaluateXPath(
`if (true()) then
[] and 1
else
(1, 2, 3)`,
null,
null,
null,
null,
{ debug: true }
),
`1: if (true()) then
async function assertError(expectedError, args: ExpressionArguments, isUpdating) {
let hasThrown = false;
try {
if (isUpdating) {
const it = evaluateUpdatingExpressionSync(...args);
executePul(it.pendingUpdateList, args);
} else {
evaluateXPath(args[0], args[1], args[2], args[3], null, args[4]);
}
} catch (e) {
hasThrown = true;
chai.assert.match(e.message, new RegExp(expectedError));
}
if (!hasThrown) {
chai.assert.fail(null, null, `Should throw error ${expectedError}.`);
}
}