Skip to content

Commit b520bac

Browse files
committed
Improve test coverage
1 parent 50e4cfe commit b520bac

File tree

4 files changed

+78
-1
lines changed

4 files changed

+78
-1
lines changed

test/specs/parsing/getBucketForSelector.tests.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,26 @@ describe('getBucketForSelector', () => {
3737
it('returns the correct bucket for expressions using the and operator, first not having a bucket', () => {
3838
assertBucketForSelector('true() and self::element()', 'type-1');
3939
});
40+
it('returns the correct bucket for expressions using the and operator, first matching nothing', () => {
41+
assertBucketForSelector(
42+
'(self::element() and self::processing-instruction()) or self::element()',
43+
'type-1',
44+
);
45+
assertBucketForSelector(
46+
'self::element() or (self::element() and self::processing-instruction())',
47+
'type-1',
48+
);
49+
});
50+
it('returns the correct bucket for expressions using nested operators, first matching everything', () => {
51+
assertBucketForSelector(
52+
'(self::element() or self::processing-instruction()) or self::element()',
53+
null,
54+
);
55+
assertBucketForSelector(
56+
'self::element() or (self::element() or self::processing-instruction())',
57+
null,
58+
);
59+
});
4060
it('returns the correct bucket for expressions using the or operator, first not having a bucket', () => {
4161
assertBucketForSelector('true() or self::element()', null);
4262
});

test/specs/parsing/operators/boolean/OrOperator.tests.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ describe('or operator', () => {
2828
);
2929
});
3030

31+
it('can parse an "or" selector with different nonoverlapping buckets that does not match', () => {
32+
jsonMlMapper.parse(['c'], documentNode);
33+
chai.assert.isFalse(
34+
evaluateXPathToBoolean('self::a or self::b', documentNode.documentElement),
35+
);
36+
});
37+
3138
it('can parse a concatenation of ors', () =>
3239
chai.assert.isTrue(
3340
evaluateXPathToBoolean(

test/specs/parsing/parseScript.tests.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,43 @@ declare %public function prefix:ok() as xs:string {
270270
chai.assert.isOk(ast);
271271
});
272272

273+
it('can parse an XPath 4.0 script', () => {
274+
const document = new Document();
275+
const ast = parseScript(`self::(a|b)`, { language: Language.XPATH_4_0_LANGUAGE }, document);
276+
277+
chai.assert.isOk(ast);
278+
});
279+
280+
it('can skip ast annotation', () => {
281+
const document = new Document();
282+
const ast = parseScript(
283+
`self::(a|b)`,
284+
{ language: Language.XPATH_4_0_LANGUAGE, annotateAst: false },
285+
document,
286+
);
287+
288+
chai.assert.isOk(ast);
289+
chai.assert.isFalse(
290+
evaluateXPathToBoolean('.//@*:type', ast),
291+
'there should be no type annotations',
292+
);
293+
});
294+
295+
it('can perform ast annotation', () => {
296+
const document = new Document();
297+
const ast = parseScript(
298+
`self::(a|b)`,
299+
{ language: Language.XPATH_4_0_LANGUAGE, annotateAst: true },
300+
document,
301+
);
302+
303+
chai.assert.isOk(ast);
304+
chai.assert.isTrue(
305+
evaluateXPathToBoolean('.//@*:type', ast),
306+
'there should be no type annotations',
307+
);
308+
});
309+
273310
it('can execute a map function within an AST', () => {
274311
const ast = parseScript('map:put($week, "1", "Monday")', {}, new Document());
275312
const result = evaluateXPathToMap(ast, null, null, {

test/specs/parsing/xquery-updating/evaluateUpdatingExpressionSync.tests.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as chai from 'chai';
22
import * as slimdom from 'slimdom';
33

4-
import { evaluateUpdatingExpressionSync, executePendingUpdateList } from 'fontoxpath';
4+
import { Language, evaluateUpdatingExpressionSync, executePendingUpdateList } from 'fontoxpath';
55
import { IPendingUpdate } from 'fontoxpath/expressions/xquery-update/IPendingUpdate';
66
import { InsertPendingUpdate } from 'fontoxpath/expressions/xquery-update/pendingUpdates/InsertPendingUpdate';
77
import { TransferablePendingUpdate } from 'fontoxpath/expressions/xquery-update/createPendingUpdateFromTransferable';
@@ -105,6 +105,19 @@ describe('evaluateUpdatingExpressionSync', () => {
105105
chai.assert.deepEqual(result.xdmValue, []);
106106
});
107107

108+
it('can evaluate an expression with XPath 4.0 used', async () => {
109+
documentNode.appendChild(documentNode.createElement('ele'));
110+
const result = evaluateUpdatingExpressionSync(
111+
'replace node not_here otherwise ele with <ele/>',
112+
documentNode,
113+
null,
114+
null,
115+
{ language: Language.XQUERY_UPDATE_4_0_LANGUAGE },
116+
);
117+
118+
chai.assert.deepEqual(result.xdmValue, []);
119+
});
120+
108121
it('properly returns the xdmValue for updating expressions', async () => {
109122
documentNode.appendChild(documentNode.createElement('ele'));
110123
const result = evaluateUpdatingExpressionSync(

0 commit comments

Comments
 (0)