aboutsummaryrefslogtreecommitdiff
path: root/test/test-document.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-02-22 16:32:38 -0500
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-02-22 16:36:17 -0500
commitbdb86e1713a196c9539306166d8dc4238adefc0d (patch)
tree3d0c50d8a73e28a33535abf6662a1f52b5f73508 /test/test-document.js
parentc1d6e5dbf177cdf41e15ff65fdf89a847f198ea1 (diff)
Test seeking functions
Diffstat (limited to 'test/test-document.js')
-rw-r--r--test/test-document.js50
1 files changed, 47 insertions, 3 deletions
diff --git a/test/test-document.js b/test/test-document.js
index 0c3c3d8e..edf6bbea 100644
--- a/test/test-document.js
+++ b/test/test-document.js
@@ -90,16 +90,17 @@ async function testDocument1() {
);
try {
- await testDocument1Inner(dom, {docRangeFromPoint, docSentenceExtract, TextSourceRange, TextSourceElement});
+ await testDocumentTextScanningFunctions(dom, {docRangeFromPoint, docSentenceExtract, TextSourceRange, TextSourceElement});
+ await testTextSourceRangeSeekFunctions(dom, {TextSourceRange});
} finally {
window.close();
}
}
-async function testDocument1Inner(dom, {docRangeFromPoint, docSentenceExtract, TextSourceRange, TextSourceElement}) {
+async function testDocumentTextScanningFunctions(dom, {docRangeFromPoint, docSentenceExtract, TextSourceRange, TextSourceElement}) {
const document = dom.window.document;
- for (const testElement of document.querySelectorAll('.test')) {
+ for (const testElement of document.querySelectorAll('.test[data-test-type=scan]')) {
// Get test parameters
let {
elementFromPointSelector,
@@ -171,6 +172,49 @@ async function testDocument1Inner(dom, {docRangeFromPoint, docSentenceExtract, T
}
}
+async function testTextSourceRangeSeekFunctions(dom, {TextSourceRange}) {
+ const document = dom.window.document;
+
+ for (const testElement of document.querySelectorAll('.test[data-test-type=text-source-range-seek]')) {
+ // Get test parameters
+ let {
+ seekNodeSelector,
+ seekNodeIsText,
+ seekOffset,
+ seekLength,
+ seekDirection,
+ expectedResultNodeSelector,
+ expectedResultNodeIsText,
+ expectedResultOffset,
+ expectedResultContent
+ } = testElement.dataset;
+
+ seekOffset = parseInt(seekOffset, 10);
+ seekLength = parseInt(seekLength, 10);
+ expectedResultOffset = parseInt(expectedResultOffset, 10);
+
+ let seekNode = testElement.querySelector(seekNodeSelector);
+ if (seekNodeIsText === 'true') {
+ seekNode = seekNode.firstChild;
+ }
+
+ let expectedResultNode = testElement.querySelector(expectedResultNodeSelector);
+ if (expectedResultNodeIsText === 'true') {
+ expectedResultNode = expectedResultNode.firstChild;
+ }
+
+ const {node, offset, content} = (
+ seekDirection === 'forward' ?
+ TextSourceRange.seekForward(seekNode, seekOffset, seekLength) :
+ TextSourceRange.seekBackward(seekNode, seekOffset, seekLength)
+ );
+
+ assert.strictEqual(node, expectedResultNode);
+ assert.strictEqual(offset, expectedResultOffset);
+ assert.strictEqual(content, expectedResultContent);
+ }
+}
+
async function main() {
await testDocument1();