Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const actualOuterHTML =
actual.nodeType === actual.DOCUMENT_NODE
? actual.documentElement.outerHTML
: actual.outerHTML;
const expectedOuterHTML =
expected.nodeType === expected.DOCUMENT_NODE
? expected.documentElement.outerHTML
: expected.outerHTML;
// Try fast string compare
if (actualOuterHTML === expectedOuterHTML) {
return;
}
if (
evaluateXPathToBoolean('deep-equal($a, $b)', null, null, {
a: actual,
b: expected
})
) {
return;
}
// Do comparison on on outer HTML for clear fail message
chai.assert.equal(actualOuterHTML, expectedOuterHTML);
}
function assertXml (actual, expected) {
// actual.normalize();
expected.normalize();
const actualOuterHTML = actual.nodeType === actual.DOCUMENT_NODE ? actual.documentElement.outerHTML : actual.outerHTML;
const expectedOuterHTML = expected.nodeType === expected.DOCUMENT_NODE ? expected.documentElement.outerHTML : expected.outerHTML;
// Try fast string compare
if (actualOuterHTML === expectedOuterHTML) {
return;
}
if (evaluateXPathToBoolean('deep-equal($a, $b)', null, null, {
a: actual,
b: expected
})) {
return;
}
// Do comparison on on outer HTML for clear fail message
chai.assert.equal(actualOuterHTML, expectedOuterHTML);
}
it('returns false if the first operand is equal to the second', () => {
chai.assert.isFalse(evaluateXPathToBoolean('1 lt 1'));
});
it('returns a float when given a float', () =>
chai.assert.isTrue(
evaluateXPathToBoolean('-(xs:float("1.5")) instance of xs:float', documentNode)
));
it('can cast strings to integers: "123"', () =>
chai.assert.isTrue(
evaluateXPathToBoolean(
'let $r := "123" cast as xs:integer return $r instance of xs:integer and $r = 123'
)
));
it('can cast decimals to integers: 123.2', () =>
() => chai.assert.isTrue(evaluateXPathToBoolean('xs:dayTimeDuration("P4DT26H") + xs:dayTimeDuration("P4DT26H") eq xs:dayTimeDuration("P10DT4H")', documentNode)));
it('can evaluate "P4DT28H" - "P4DT26H"',
it('can evaluate "P11Y10M" * 2', () =>
chai.assert.isTrue(
evaluateXPathToBoolean(
'xs:yearMonthDuration("P1Y10M") * xs:double("2") eq xs:yearMonthDuration("P44M")',
documentNode
)
));
it('can evaluate "P11Y10M" div 2', () =>
it('xs:unsignedLong()', () =>
chai.assert.isTrue(
evaluateXPathToBoolean(
'xs:unsignedLong("10") instance of xs:unsignedLong+',
documentNode
)
));
it('xs:unsignedInt()', () =>
it('can cast doubles to strings: INF', () =>
chai.assert.isTrue(
evaluateXPathToBoolean(
'let $r := xs:double("INF") cast as xs:string return $r instance of xs:string and $r = "INF"'
)
));
it('can cast doubles to strings: -INF', () =>
() =>
evaluateXPathToBoolean(
'declare default function namespace "http://example.com"; declare default function namespace "http://example.com"; declare %private function lt() as item()*{ true() }; Q{http://example.com}lt()',
documentNode,
undefined,
{},
{ language: evaluateXPath.XQUERY_3_1_LANGUAGE }
),
'XQST0066: A Prolog may contain at most one default function namespace declaration.'