You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@annotator.apache.org by ge...@apache.org on 2020/05/25 18:03:26 UTC

[incubator-annotator] 02/08: Add tests with prefix, suffix, no matches

This is an automated email from the ASF dual-hosted git repository.

gerben pushed a commit to branch dom-tests
in repository https://gitbox.apache.org/repos/asf/incubator-annotator.git

commit c9643a93924f5223158763172a84b4ee022bce10
Author: Gerben <ge...@treora.com>
AuthorDate: Mon May 25 13:01:33 2020 +0200

    Add tests with prefix, suffix, no matches
---
 packages/dom/test/text-quote-match.ts | 124 ++++++++++++++++++++++++++++++++++
 1 file changed, 124 insertions(+)

diff --git a/packages/dom/test/text-quote-match.ts b/packages/dom/test/text-quote-match.ts
index ac5b13a..77f8bd4 100644
--- a/packages/dom/test/text-quote-match.ts
+++ b/packages/dom/test/text-quote-match.ts
@@ -172,6 +172,130 @@ const testCases: {
       },
     ]
   },
+  'no matches': {
+    html: '<b>lorem ipsum dolor amet yada yada</b>',
+    selector: {
+      type: 'TextQuoteSelector',
+      exact: 'holy grail',
+    },
+    expected: []
+  },
+  'with prefix': {
+    html: '<b>lorem ipsum dolor amet yada yada</b>',
+    selector: {
+      type: 'TextQuoteSelector',
+      exact: 'yada',
+      prefix: 't ',
+    },
+    expected: [
+      {
+        startContainerXPath: '//b/text()',
+        startOffset: 23,
+        endContainerXPath: '//b/text()',
+        endOffset: 27,
+      },
+    ]
+  },
+  'with suffix': {
+    html: '<b>lorem ipsum dolor amet yada yada</b>',
+    selector: {
+      type: 'TextQuoteSelector',
+      exact: 'o',
+      suffix: 'l',
+    },
+    expected: [
+      {
+        startContainerXPath: '//b/text()',
+        startOffset: 13,
+        endContainerXPath: '//b/text()',
+        endOffset: 14,
+      },
+    ]
+  },
+  'with prefix and suffix': {
+    html: '<b>lorem ipsum dolor amet yada yada</b>',
+    selector: {
+      type: 'TextQuoteSelector',
+      exact: 'o',
+      prefix: 'l',
+      suffix: 're',
+    },
+    expected: [
+      {
+        startContainerXPath: '//b/text()',
+        startOffset: 1,
+        endContainerXPath: '//b/text()',
+        endOffset: 2,
+      },
+    ]
+  },
+  'with prefix and suffix, two matches': {
+    html: '<b>lorem ipsum dolor amet yada yada</b>',
+    selector: {
+      type: 'TextQuoteSelector',
+      exact: 'o',
+      prefix: 'l',
+      suffix: 'r',
+    },
+    expected: [
+      {
+        startContainerXPath: '//b/text()',
+        startOffset: 1,
+        endContainerXPath: '//b/text()',
+        endOffset: 2,
+      },
+      {
+        startContainerXPath: '//b/text()',
+        startOffset: 15,
+        endContainerXPath: '//b/text()',
+        endOffset: 16,
+      },
+    ]
+  },
+  'with prefix, no matches': {
+    html: '<b>lorem ipsum dolor amet yada yada</b>',
+    selector: {
+      type: 'TextQuoteSelector',
+      exact: 'dolor',
+      prefix: 'oopsum ',
+    },
+    expected: []
+  },
+  'with suffix, no matches': {
+    html: '<b>lorem ipsum dolor amet yada yada</b>',
+    selector: {
+      type: 'TextQuoteSelector',
+      exact: 'dolor',
+      suffix: ' amot',
+    },
+    expected: []
+  },
+  'with suffix, no matches due to whitespace': {
+    html: '<b>lorem ipsum dolor amet yada yada</b>',
+    selector: {
+      type: 'TextQuoteSelector',
+      exact: 'dolor',
+      suffix: 'a',
+    },
+    expected: []
+  },
+  'with empty prefix and suffix': {
+    html: '<b>lorem ipsum dolor amet yada yada</b>',
+    selector: {
+      type: 'TextQuoteSelector',
+      exact: 'dolor am',
+      prefix: '',
+      suffix: '',
+    },
+    expected: [
+      {
+        startContainerXPath: '//b/text()',
+        startOffset: 12,
+        endContainerXPath: '//b/text()',
+        endOffset: 20,
+      },
+    ]
+  },
 };
 
 describe('createTextQuoteSelectorMatcher', () => {