This is an automated email from the ASF dual-hosted git repository. gerben pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-annotator.git
commit aeb2cd8188bcbd1cd17fea0f076f5b5a95493701 Author: Gerben <[email protected]> AuthorDate: Fri Jun 25 17:16:33 2021 +0200 Add cases for matches in multiple nodes In the case of DOM changes, a different error occurs depending on whether the matches are in the same or different text nodes. With different nodes, the infinite loop behaviour occurs. --- packages/dom/test/text-quote/match-cases.ts | 52 +++++++++++++++++++++++++++-- packages/dom/test/text-quote/match.test.ts | 2 +- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/packages/dom/test/text-quote/match-cases.ts b/packages/dom/test/text-quote/match-cases.ts index 8d344d3..8948b78 100644 --- a/packages/dom/test/text-quote/match-cases.ts +++ b/packages/dom/test/text-quote/match-cases.ts @@ -119,7 +119,7 @@ export const testCases: { }, ], }, - 'two matches': { + 'two matches in one node': { html: '<b>lorem ipsum dolor amet yada yada</b>', selector: { type: 'TextQuoteSelector', @@ -140,7 +140,34 @@ export const testCases: { }, ], }, - 'overlapping matches': { + 'matches in multiple nodes': { + html: `<p>Match again and <b>again </b>and <i>again</i>!`, + selector: { + type: 'TextQuoteSelector', + exact: 'again', + }, + expected: [ + { + startContainerXPath: '//p/text()[1]', + startOffset: 6, + endContainerXPath: '//p/text()[1]', + endOffset: 11, + }, + { + startContainerXPath: '//b/text()', + startOffset: 0, + endContainerXPath: '//b/text()', + endOffset: 5, + }, + { + startContainerXPath: '//i/text()', + startOffset: 0, + endContainerXPath: '//i/text()', + endOffset: 5, + }, + ], + }, + 'overlapping matches in one node': { html: '<b>bananas</b>', selector: { type: 'TextQuoteSelector', @@ -161,6 +188,27 @@ export const testCases: { }, ], }, + 'overlapping matches stretching multiple nodes': { + html: '<b>bana<i>na</i>nas</b>', + selector: { + type: 'TextQuoteSelector', + exact: 'anana', + }, + expected: [ + { + startContainerXPath: '//b/text()[1]', + startOffset: 1, + endContainerXPath: '//i/text()', + endOffset: 2, + }, + { + startContainerXPath: '//b/text()[1]', + startOffset: 3, + endContainerXPath: '//b/text()[2]', + endOffset: 2, + }, + ], + }, 'no matches': { html: '<b>lorem ipsum dolor amet yada yada</b>', selector: { diff --git a/packages/dom/test/text-quote/match.test.ts b/packages/dom/test/text-quote/match.test.ts index cfb0753..60819a6 100644 --- a/packages/dom/test/text-quote/match.test.ts +++ b/packages/dom/test/text-quote/match.test.ts @@ -173,7 +173,7 @@ describe('createTextQuoteSelectorMatcher', () => { }); it.skip('is resistant to splitting text nodes', async () => { - const { html, selector, expected } = testCases['two matches']; + const { html, selector, expected } = testCases['matches in multiple nodes']; const doc = domParser.parseFromString(html, 'text/html'); const matcher = createTextQuoteSelectorMatcher(selector);
