How to use the fontoxpath.evaluateXPathToNodes function in fontoxpath

To help you get started, we’ve selected a few fontoxpath examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github FontoXML / fontoxpath / test / specs / parsing / usesHints.tests.ts View on Github external
it('skips the subtree for outermost() with tail', () => {
		jsonMlMapper.parse(['root', ['foo', ['foo']]], documentNode);
		const descendant = documentNode.documentElement.firstChild.firstChild;
		// It is successful when the dom facade does not throw
		const nodes = evaluateXPathToNodes(
			'outermost(tail(descendant::node()))',
			documentNode,
			buildDomFacade(descendant),
			null,
			{ language: evaluateXPath.XQUERY_3_1_LANGUAGE }
		);

		chai.assert.deepEqual(nodes, [documentNode.documentElement.firstChild]);
	});
github FontoXML / fontoxpath / test / specs / parsing / usesHints.tests.ts View on Github external
it('skips the subtree for outermost() in debug mode', () => {
		jsonMlMapper.parse(['root', ['foo', ['foo']]], documentNode);
		const descendant = documentNode.documentElement.firstChild.firstChild;
		// It is successful when the dom facade does not throw
		const nodes = evaluateXPathToNodes(
			'outermost(descendant::foo)',
			documentNode,
			buildDomFacade(descendant),
			null,
			{
				debug: true
			}
		);

		chai.assert.deepEqual(nodes, [documentNode.documentElement.firstChild]);
	});
});
github FontoXML / fontoxpath / test / qt3tests.ts View on Github external
function createEnvironment(cwd, environmentNode) {
	const fileName = evaluateXPathToString('source[@role="."]/@file', environmentNode);
	const variables = evaluateXPathToNodes('source[@role!="."]', environmentNode).reduce(
		(varsByName, variable) =>
			Object.assign(varsByName, {
				[evaluateXPathToString('@role', variable).substr(1)]: getFile(
					(cwd ? cwd + '/' : '') + evaluateXPathToString('@file', variable)
				)
			}),
		{}
	);

	// Params area also variables. But different
	evaluateXPathToNodes('param', environmentNode).forEach(paramNode => {
		variables[evaluateXPathToString('@name', paramNode)] = evaluateXPath(
			evaluateXPathToString('@select', paramNode)
		);
		console.log(variables);
	});

	const namespaces = evaluateXPathToMap(
		'(namespace!map:entry(@prefix/string(), @uri/string())) => map:merge()',
		environmentNode
	);

	return {
		contextNode: fileName ? getFile((cwd ? cwd + '/' : '') + fileName) : null,
		variables,
		namespaceResolver: Object.keys(namespaces).length ? prefix => namespaces[prefix] : null
	};
github FontoXML / fontoxpath / test / qt3tests.ts View on Github external
createProcessingInstruction: assertNode.ownerDocument.createProcessingInstruction.bind(
			assertNode.ownerDocument
		),
		createTextNode: assertNode.ownerDocument.createTextNode.bind(assertNode.ownerDocument)
	};

	switch (assertNode.localName) {
		case 'all-of': {
			const asserts = evaluateXPathToNodes('*', assertNode).map(innerAssertNode =>
				createAsserter(baseUrl, innerAssertNode, language)
			);
			return (xpath, contextNode, variablesInScope, namespaceResolver) =>
				asserts.forEach(a => a(xpath, contextNode, variablesInScope, namespaceResolver));
		}
		case 'any-of': {
			const asserts = evaluateXPathToNodes('*', assertNode).map(innerAssertNode =>
				createAsserter(baseUrl, innerAssertNode, language)
			);
			return (xpath, contextNode, variablesInScope, namespaceResolver) => {
				const errors = [];
				chai.assert(
					asserts.some(a => {
						try {
							a(xpath, contextNode, variablesInScope, namespaceResolver);
						} catch (error) {
							if (error instanceof TypeError) {
								// TypeErrors are always errors
								throw error;
							}
							errors.push(error);
							return false;
						}
github FontoXML / fontoxpath / test / specs / parsing / operators / compares / Compare.tests.ts View on Github external
it('works over one empty sequence and a filled one', () => {
		chai.assert.deepEqual(evaluateXPathToNodes('() eq (true())'), []);
	});
github FontoXML / fontoxpath / test / specs / parsing / path / PathExpression.tests.ts View on Github external
it('supports relative paths', () => {
		jsonMlMapper.parse(['someNode', ['someChildNode']], documentNode);
		chai.assert.deepEqual(evaluateXPathToNodes('someChildNode', documentNode.documentElement), [
			documentNode.documentElement.firstChild
		]);
	});
github FontoXML / fontoxpath / test / xqutsTests.js View on Github external
function buildTestCases (testGroup) {
	evaluateXPathToNodes('test-group | test-case', testGroup).forEach(test => {
		switch (test.localName) {
			case 'test-group': {
				const groupName = evaluateXPathToString('(@name, string(GroupInfo/title), string(GroupInfo/description))[. != ""][1]', test);
				describe(groupName, () => buildTestCases(test));
				break;
			}
			case 'test-case': {
				const testName = evaluateXPathToString('(@name, description)[. != ""][1]', test);

				if (unrunnableTestCasesByName.includes(testName)) {
					it.skip(testName);
					return;
				}

				it(testName, async () => await runTestCase(testName, test));
				break;
github FontoXML / fontoxpath / test / specs / parsing / evaluateXPath.tests.ts View on Github external
it('Keeps nodes nodes', () =>
			chai.assert.deepEqual(evaluateXPathToNodes('.', documentNode, domFacade), [
				documentNode
			]));
github FontoXML / fontoxpath / test / xqutsTests.js View on Github external
}
			});
		}

		switch (outputFile.compare) {
			case 'XML': {
				const actual = xdmValue ? xdmValue[0].value : evaluateXPathToFirstNode(...args);
				const expected = actual.nodeType === actual.DOCUMENT_NODE ?
					parser.parseFromString(expectedString) :
					parser.parseFromString(expectedString).documentElement;

				catchAssertion(() => assertXml(actual, expected));
				break;
			}
			case 'Fragment': {
				const actualNodes = xdmValue ? xdmValue.map(nodeValue => nodeValue.value) : evaluateXPathToNodes(...args);

				catchAssertion(() => assertFragment(actualNodes, expectedString));
				break;
			}
			case 'Text': {
				if (xdmValue) {
					throw new Error('Not yet supported: Updating query with text assertion.');
				}
				const actual = evaluateXPathToString(...args);
				const actualNodes = [new slimdom.Document().createTextNode(actual)];

				catchAssertion(() => assertFragment(actualNodes, expectedString));
				break;
			}
			default:
				throw new Error('Compare ' + outputFile.compare + ' is not supported.');
github FontoXML / fontoxpath / test / specs / parsing / axes / PrecedingAxis.tests.js View on Github external
		chai.assert.throws(() => evaluateXPathToNodes('preceding::*', null), 'XPDY0002');
	});