Skip to content

Commit

Permalink
Add tests for uncovered lines
Browse files Browse the repository at this point in the history
  • Loading branch information
DrRataplan committed Jul 12, 2024
1 parent ba0e308 commit 2d9d9a5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/expressions/functions/builtInFunctions_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ const fnGenerateId: FunctionDefinitionType = (
throw new Error('XPTY0004: The context item must be a node.');
}
const node = nodeValue.first().value as NodePointer;

return sequenceFactory.singleton(createAtomicValue(generateId(node), ValueType.XSSTRING));
};

Expand Down
12 changes: 12 additions & 0 deletions test/specs/parsing/functions/functions.node.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ describe('functions over nodes', () => {
);
});

it('returns the empty string for the empty sequence', () => {
jsonMlMapper.parse(['someElement'], documentNode);
chai.assert.isTrue(evaluateXPathToBoolean('generate-id(()) = ""', documentNode));
});

it('throws the correct error when the context item is not a node', () => {
chai.assert.throws(
() => evaluateXPathToBoolean('"not a node" ! generate-id()'),
'XPTY0004',
);
});

it('returns the same value for subsequent calls', () => {
jsonMlMapper.parse(['someElement'], documentNode);
const id = evaluateXPathToString('generate-id(/)', documentNode);
Expand Down

0 comments on commit 2d9d9a5

Please sign in to comment.