/
operatorPrecedence.tests.js
30 lines (27 loc) · 1.11 KB
/
operatorPrecedence.tests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import chai from 'chai';
import * as slimdom from 'slimdom';
import jsonMlMapper from 'test-helpers/jsonMlMapper';
import {
evaluateXPathToBoolean
} from 'fontoxpath';
let documentNode;
beforeEach(() => {
documentNode = new slimdom.Document();
});
describe('operators', () => {
it('uses correct operator precedence', () => {
jsonMlMapper.parse([
'someParentElement',
[
'someMiddleElement',
{ someAttribute: 'someValue' },
['someOtherElement']
]
], documentNode);
chai.assert.isTrue(evaluateXPathToBoolean('(child::someElement and ancestor::someParentElement) or @someAttribute=\'someValue\'', documentNode.documentElement.firstChild));
// The other way around
chai.assert.isTrue(evaluateXPathToBoolean('(child::someOtherElement and ancestor::someParentElement) or @someAttribute=\'someOtherValue\'', documentNode.documentElement.firstChild));
// Changes to testcase A: Operator order changed because of parentheses
chai.assert.isFalse(evaluateXPathToBoolean('child::someElement and (ancestor::someParentElement or @someAttribute="someValue")', documentNode.documentElement.firstChild));
});
});