diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/data/html/test-document1.html | 158 | ||||
-rw-r--r-- | test/test-document.js | 50 |
2 files changed, 205 insertions, 3 deletions
diff --git a/test/data/html/test-document1.html b/test/data/html/test-document1.html index 00cc8524..0754a314 100644 --- a/test/data/html/test-document1.html +++ b/test/data/html/test-document1.html @@ -13,6 +13,7 @@ <div class="test" + data-test-type="scan" data-element-from-point-selector="span" data-caret-range-from-point-selector="span" data-start-node-selector="span" @@ -28,6 +29,7 @@ <div class="test" + data-test-type="scan" data-element-from-point-selector="span" data-caret-range-from-point-selector="span" data-start-node-selector="span" @@ -43,6 +45,7 @@ <div class="test" + data-test-type="scan" data-element-from-point-selector="input" data-caret-range-from-point-selector="input" data-start-node-selector="input" @@ -59,6 +62,7 @@ <div class="test" + data-test-type="scan" data-element-from-point-selector="textarea" data-caret-range-from-point-selector="textarea" data-start-node-selector="textarea" @@ -75,6 +79,7 @@ <div class="test" + data-test-type="scan" data-element-from-point-selector="button" data-caret-range-from-point-selector="button" data-start-node-selector="button" @@ -90,6 +95,7 @@ <div class="test" + data-test-type="scan" data-element-from-point-selector="img" data-caret-range-from-point-selector="img" data-start-node-selector="img" @@ -102,5 +108,157 @@ <img src="data:image/gif;base64,R0lGODdhBwAHAIABAAAAAP///ywAAAAABwAHAAACDIRvEaC32FpCbEkKCgA7" alt="よみちゃん" title="よみちゃん" style="width: 70px; height: 70px; image-rendering: crisp-edges; image-rendering: pixelated; display: block;" /> </div> + <div + class="test" + data-test-type="text-source-range-seek" + data-seek-node-selector="span:nth-of-type(1)" + data-seek-node-is-text="true" + data-seek-offset="0" + data-seek-length="149" + data-seek-direction="forward" + data-expected-result-node-selector="span:nth-of-type(1)" + data-expected-result-node-is-text="true" + data-expected-result-offset="149" + data-expected-result-content=" + あいうえお + かきくけこ + さしすせそ + たちつてと + なにぬねの + はひふへほ + まみむめも + や ゆ よ + らりるれろ + わゐ ゑを + " + > + <span> + あいうえお + かきくけこ + さしすせそ + たちつてと + なにぬねの + はひふへほ + まみむめも + や ゆ よ + らりるれろ + わゐ ゑを + </span><span>trailing content</span> + </div> + + <div + class="test" + data-test-type="text-source-range-seek" + data-seek-node-selector="span:nth-of-type(1)" + data-seek-node-is-text="true" + data-seek-offset="149" + data-seek-length="149" + data-seek-direction="backward" + data-expected-result-node-selector="span:nth-of-type(1)" + data-expected-result-node-is-text="true" + data-expected-result-offset="0" + data-expected-result-content=" + あいうえお + かきくけこ + さしすせそ + たちつてと + なにぬねの + はひふへほ + まみむめも + や ゆ よ + らりるれろ + わゐ ゑを + " + > + <span> + あいうえお + かきくけこ + さしすせそ + たちつてと + なにぬねの + はひふへほ + まみむめも + や ゆ よ + らりるれろ + わゐ ゑを + </span><span>trailing content</span> + </div> + + <div + class="test" + data-test-type="text-source-range-seek" + data-seek-node-selector="span:nth-of-type(1)" + data-seek-node-is-text="true" + data-seek-offset="0" + data-seek-length="150" + data-seek-direction="forward" + data-expected-result-node-selector="span:nth-of-type(2)" + data-expected-result-node-is-text="true" + data-expected-result-offset="1" + data-expected-result-content=" + あいうえお + かきくけこ + さしすせそ + たちつてと + なにぬねの + はひふへほ + まみむめも + や ゆ よ + らりるれろ + わゐ ゑを + t" + > + <span> + あいうえお + かきくけこ + さしすせそ + たちつてと + なにぬねの + はひふへほ + まみむめも + や ゆ よ + らりるれろ + わゐ ゑを + </span><span>trailing content</span> + </div> + + <div + class="test" + data-test-type="text-source-range-seek" + data-seek-node-selector="span:nth-of-type(2)" + data-seek-node-is-text="true" + data-seek-offset="1" + data-seek-length="150" + data-seek-direction="backward" + data-expected-result-node-selector="span:nth-of-type(1)" + data-expected-result-node-is-text="true" + data-expected-result-offset="0" + data-expected-result-content=" + あいうえお + かきくけこ + さしすせそ + たちつてと + なにぬねの + はひふへほ + まみむめも + や ゆ よ + らりるれろ + わゐ ゑを + t" + > + <span> + あいうえお + かきくけこ + さしすせそ + たちつてと + なにぬねの + はひふへほ + まみむめも + や ゆ よ + らりるれろ + わゐ ゑを + </span><span>trailing content</span> + </div> + </body> </html>
\ No newline at end of file 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(); |