Skip to content

Commit

Permalink
Improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
DrRataplan committed Nov 22, 2024
1 parent 50e4cfe commit b520bac
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 1 deletion.
20 changes: 20 additions & 0 deletions test/specs/parsing/getBucketForSelector.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,26 @@ describe('getBucketForSelector', () => {
it('returns the correct bucket for expressions using the and operator, first not having a bucket', () => {
assertBucketForSelector('true() and self::element()', 'type-1');
});
it('returns the correct bucket for expressions using the and operator, first matching nothing', () => {
assertBucketForSelector(
'(self::element() and self::processing-instruction()) or self::element()',
'type-1',
);
assertBucketForSelector(
'self::element() or (self::element() and self::processing-instruction())',
'type-1',
);
});
it('returns the correct bucket for expressions using nested operators, first matching everything', () => {
assertBucketForSelector(
'(self::element() or self::processing-instruction()) or self::element()',
null,
);
assertBucketForSelector(
'self::element() or (self::element() or self::processing-instruction())',
null,
);
});
it('returns the correct bucket for expressions using the or operator, first not having a bucket', () => {
assertBucketForSelector('true() or self::element()', null);
});
Expand Down
7 changes: 7 additions & 0 deletions test/specs/parsing/operators/boolean/OrOperator.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ describe('or operator', () => {
);
});

it('can parse an "or" selector with different nonoverlapping buckets that does not match', () => {
jsonMlMapper.parse(['c'], documentNode);
chai.assert.isFalse(
evaluateXPathToBoolean('self::a or self::b', documentNode.documentElement),
);
});

it('can parse a concatenation of ors', () =>
chai.assert.isTrue(
evaluateXPathToBoolean(
Expand Down
37 changes: 37 additions & 0 deletions test/specs/parsing/parseScript.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,43 @@ declare %public function prefix:ok() as xs:string {
chai.assert.isOk(ast);
});

it('can parse an XPath 4.0 script', () => {
const document = new Document();
const ast = parseScript(`self::(a|b)`, { language: Language.XPATH_4_0_LANGUAGE }, document);

chai.assert.isOk(ast);
});

it('can skip ast annotation', () => {
const document = new Document();
const ast = parseScript(
`self::(a|b)`,
{ language: Language.XPATH_4_0_LANGUAGE, annotateAst: false },
document,
);

chai.assert.isOk(ast);
chai.assert.isFalse(
evaluateXPathToBoolean('.//@*:type', ast),
'there should be no type annotations',
);
});

it('can perform ast annotation', () => {
const document = new Document();
const ast = parseScript(
`self::(a|b)`,
{ language: Language.XPATH_4_0_LANGUAGE, annotateAst: true },
document,
);

chai.assert.isOk(ast);
chai.assert.isTrue(
evaluateXPathToBoolean('.//@*:type', ast),
'there should be no type annotations',
);
});

it('can execute a map function within an AST', () => {
const ast = parseScript('map:put($week, "1", "Monday")', {}, new Document());
const result = evaluateXPathToMap(ast, null, null, {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as chai from 'chai';
import * as slimdom from 'slimdom';

import { evaluateUpdatingExpressionSync, executePendingUpdateList } from 'fontoxpath';
import { Language, evaluateUpdatingExpressionSync, executePendingUpdateList } from 'fontoxpath';
import { IPendingUpdate } from 'fontoxpath/expressions/xquery-update/IPendingUpdate';
import { InsertPendingUpdate } from 'fontoxpath/expressions/xquery-update/pendingUpdates/InsertPendingUpdate';
import { TransferablePendingUpdate } from 'fontoxpath/expressions/xquery-update/createPendingUpdateFromTransferable';
Expand Down Expand Up @@ -105,6 +105,19 @@ describe('evaluateUpdatingExpressionSync', () => {
chai.assert.deepEqual(result.xdmValue, []);
});

it('can evaluate an expression with XPath 4.0 used', async () => {
documentNode.appendChild(documentNode.createElement('ele'));
const result = evaluateUpdatingExpressionSync(
'replace node not_here otherwise ele with <ele/>',
documentNode,
null,
null,
{ language: Language.XQUERY_UPDATE_4_0_LANGUAGE },
);

chai.assert.deepEqual(result.xdmValue, []);
});

it('properly returns the xdmValue for updating expressions', async () => {
documentNode.appendChild(documentNode.createElement('ele'));
const result = evaluateUpdatingExpressionSync(
Expand Down

0 comments on commit b520bac

Please sign in to comment.