summaryrefslogtreecommitdiff
path: root/test/test-document.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-06-21 16:07:51 -0400
committerGitHub <noreply@github.com>2020-06-21 16:07:51 -0400
commite23504613f8526b90a497512c086ed48e66cde95 (patch)
tree98db1a607ba40659d727e0083f2e45032a53e3a9 /test/test-document.js
parent4ebee3e17c2d536da7de33d16c2e44c54c4c8e51 (diff)
Use DOMTextScanner (#536)
* Use DOMTextScanner instead of TextSourceRange.seek* * Move getNodesInRange to dom.js * Move anyNodeMatchesSelector to dom.js * Remove unused functions * Update tests * Add layoutAwareScan option * Use layoutAwareScan for source and sentence scanning * Remove unused IGNORE_TEXT_PATTERN
Diffstat (limited to 'test/test-document.js')
-rw-r--r--test/test-document.js14
1 files changed, 8 insertions, 6 deletions
diff --git a/test/test-document.js b/test/test-document.js
index 0d9026db..ba7acc49 100644
--- a/test/test-document.js
+++ b/test/test-document.js
@@ -94,10 +94,12 @@ async function testDocument1() {
const vm = new VM({document, window, Range, Node});
vm.execute([
'mixed/js/dom.js',
+ 'fg/js/dom-text-scanner.js',
'fg/js/source.js',
'fg/js/document.js'
]);
- const [TextSourceRange, TextSourceElement, docRangeFromPoint, docSentenceExtract] = vm.get([
+ const [DOMTextScanner, TextSourceRange, TextSourceElement, docRangeFromPoint, docSentenceExtract] = vm.get([
+ 'DOMTextScanner',
'TextSourceRange',
'TextSourceElement',
'docRangeFromPoint',
@@ -106,7 +108,7 @@ async function testDocument1() {
try {
await testDocumentTextScanningFunctions(dom, {docRangeFromPoint, docSentenceExtract, TextSourceRange, TextSourceElement});
- await testTextSourceRangeSeekFunctions(dom, {TextSourceRange});
+ await testTextSourceRangeSeekFunctions(dom, {DOMTextScanner});
} finally {
window.close();
}
@@ -179,7 +181,7 @@ async function testDocumentTextScanningFunctions(dom, {docRangeFromPoint, docSen
if (source === null) { continue; }
// Test docSentenceExtract
- const sentenceActual = docSentenceExtract(source, sentenceExtent).text;
+ const sentenceActual = docSentenceExtract(source, sentenceExtent, false).text;
assert.strictEqual(sentenceActual, sentence);
// Clean
@@ -187,7 +189,7 @@ async function testDocumentTextScanningFunctions(dom, {docRangeFromPoint, docSen
}
}
-async function testTextSourceRangeSeekFunctions(dom, {TextSourceRange}) {
+async function testTextSourceRangeSeekFunctions(dom, {DOMTextScanner}) {
const document = dom.window.document;
for (const testElement of document.querySelectorAll('.test[data-test-type=text-source-range-seek]')) {
@@ -220,8 +222,8 @@ async function testTextSourceRangeSeekFunctions(dom, {TextSourceRange}) {
const {node, offset, content} = (
seekDirection === 'forward' ?
- TextSourceRange.seekForward(seekNode, seekOffset, seekLength) :
- TextSourceRange.seekBackward(seekNode, seekOffset, seekLength)
+ new DOMTextScanner(seekNode, seekOffset, true, false).seek(seekLength) :
+ new DOMTextScanner(seekNode, seekOffset, true, false).seek(-seekLength)
);
assert.strictEqual(node, expectedResultNode);