Test seeking functions
This commit is contained in:
parent
c1d6e5dbf1
commit
bdb86e1713
@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
<div
|
<div
|
||||||
class="test"
|
class="test"
|
||||||
|
data-test-type="scan"
|
||||||
data-element-from-point-selector="span"
|
data-element-from-point-selector="span"
|
||||||
data-caret-range-from-point-selector="span"
|
data-caret-range-from-point-selector="span"
|
||||||
data-start-node-selector="span"
|
data-start-node-selector="span"
|
||||||
@ -28,6 +29,7 @@
|
|||||||
|
|
||||||
<div
|
<div
|
||||||
class="test"
|
class="test"
|
||||||
|
data-test-type="scan"
|
||||||
data-element-from-point-selector="span"
|
data-element-from-point-selector="span"
|
||||||
data-caret-range-from-point-selector="span"
|
data-caret-range-from-point-selector="span"
|
||||||
data-start-node-selector="span"
|
data-start-node-selector="span"
|
||||||
@ -43,6 +45,7 @@
|
|||||||
|
|
||||||
<div
|
<div
|
||||||
class="test"
|
class="test"
|
||||||
|
data-test-type="scan"
|
||||||
data-element-from-point-selector="input"
|
data-element-from-point-selector="input"
|
||||||
data-caret-range-from-point-selector="input"
|
data-caret-range-from-point-selector="input"
|
||||||
data-start-node-selector="input"
|
data-start-node-selector="input"
|
||||||
@ -59,6 +62,7 @@
|
|||||||
|
|
||||||
<div
|
<div
|
||||||
class="test"
|
class="test"
|
||||||
|
data-test-type="scan"
|
||||||
data-element-from-point-selector="textarea"
|
data-element-from-point-selector="textarea"
|
||||||
data-caret-range-from-point-selector="textarea"
|
data-caret-range-from-point-selector="textarea"
|
||||||
data-start-node-selector="textarea"
|
data-start-node-selector="textarea"
|
||||||
@ -75,6 +79,7 @@
|
|||||||
|
|
||||||
<div
|
<div
|
||||||
class="test"
|
class="test"
|
||||||
|
data-test-type="scan"
|
||||||
data-element-from-point-selector="button"
|
data-element-from-point-selector="button"
|
||||||
data-caret-range-from-point-selector="button"
|
data-caret-range-from-point-selector="button"
|
||||||
data-start-node-selector="button"
|
data-start-node-selector="button"
|
||||||
@ -90,6 +95,7 @@
|
|||||||
|
|
||||||
<div
|
<div
|
||||||
class="test"
|
class="test"
|
||||||
|
data-test-type="scan"
|
||||||
data-element-from-point-selector="img"
|
data-element-from-point-selector="img"
|
||||||
data-caret-range-from-point-selector="img"
|
data-caret-range-from-point-selector="img"
|
||||||
data-start-node-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;" />
|
<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>
|
||||||
|
|
||||||
|
<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>
|
</body>
|
||||||
</html>
|
</html>
|
@ -90,16 +90,17 @@ async function testDocument1() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await testDocument1Inner(dom, {docRangeFromPoint, docSentenceExtract, TextSourceRange, TextSourceElement});
|
await testDocumentTextScanningFunctions(dom, {docRangeFromPoint, docSentenceExtract, TextSourceRange, TextSourceElement});
|
||||||
|
await testTextSourceRangeSeekFunctions(dom, {TextSourceRange});
|
||||||
} finally {
|
} finally {
|
||||||
window.close();
|
window.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function testDocument1Inner(dom, {docRangeFromPoint, docSentenceExtract, TextSourceRange, TextSourceElement}) {
|
async function testDocumentTextScanningFunctions(dom, {docRangeFromPoint, docSentenceExtract, TextSourceRange, TextSourceElement}) {
|
||||||
const document = dom.window.document;
|
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
|
// Get test parameters
|
||||||
let {
|
let {
|
||||||
elementFromPointSelector,
|
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() {
|
async function main() {
|
||||||
await testDocument1();
|
await testDocument1();
|
||||||
|
Loading…
Reference in New Issue
Block a user