Test seeking functions

This commit is contained in:
toasted-nutbread 2020-02-22 16:32:38 -05:00
parent c1d6e5dbf1
commit bdb86e1713
2 changed files with 205 additions and 3 deletions

View File

@ -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="
あいうえお
かきくけこ
さしすせそ
たちつてと
なにぬねの
はひふへほ
まみむめも
&#x3000;&#x3000;
らりるれろ
わゐ&#x3000;ゑを
"
>
<span>
あいうえお
かきくけこ
さしすせそ
たちつてと
なにぬねの
はひふへほ
まみむめも
&#x3000;&#x3000;
らりるれろ
わゐ&#x3000;ゑを
</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="
あいうえお
かきくけこ
さしすせそ
たちつてと
なにぬねの
はひふへほ
まみむめも
&#x3000;&#x3000;
らりるれろ
わゐ&#x3000;ゑを
"
>
<span>
あいうえお
かきくけこ
さしすせそ
たちつてと
なにぬねの
はひふへほ
まみむめも
&#x3000;&#x3000;
らりるれろ
わゐ&#x3000;ゑを
</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="
あいうえお
かきくけこ
さしすせそ
たちつてと
なにぬねの
はひふへほ
まみむめも
&#x3000;&#x3000;
らりるれろ
わゐ&#x3000;ゑを
t"
>
<span>
あいうえお
かきくけこ
さしすせそ
たちつてと
なにぬねの
はひふへほ
まみむめも
&#x3000;&#x3000;
らりるれろ
わゐ&#x3000;ゑを
</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="
あいうえお
かきくけこ
さしすせそ
たちつてと
なにぬねの
はひふへほ
まみむめも
&#x3000;&#x3000;
らりるれろ
わゐ&#x3000;ゑを
t"
>
<span>
あいうえお
かきくけこ
さしすせそ
たちつてと
なにぬねの
はひふへほ
まみむめも
&#x3000;&#x3000;
らりるれろ
わゐ&#x3000;ゑを
</span><span>trailing content</span>
</div>
</body>
</html>

View File

@ -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();