Skip to content

Commit

Permalink
Test case
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmaa committed Oct 25, 2024
1 parent 72a3477 commit 19e7b54
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
22 changes: 20 additions & 2 deletions test/data/html/dom-text-scanner.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<h1>DOMTextScanner Tests</h1>

<test-description>Automated test cases for DOMTextScanner.</test-description>

<!--
<test-case
data-test-data='{
"node": "div:nth-of-type(1)",
Expand Down Expand Up @@ -389,7 +389,25 @@ <h1>DOMTextScanner Tests</h1>
>
<test-description>Skip content with user-select:none <em>and</em> a transparent color.</test-description>
<div>小ぢん<span style="user-select: none; color: rgba(0, 0, 0, 0);">content</span>まり1</div>
</test-case>
</test-case> -->

<test-case
data-test-data='{
"node": "span::text",
"offset": 0,
"length": -10,
"stopAtWordBoundary": true,
"expected": {
"node": "span::text",
"offset": 0,
"content": "read"
}
}'
>
<test-description>Stops at word boundary</test-description>
<div>
<span>read</span>
</div>
</test-case>
</body>
</html>
5 changes: 4 additions & 1 deletion test/dom-text-scanner.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ describe('DOMTextScanner seek tests', () => {
forcePreserveWhitespace,
generateLayoutContent,
reversible,
stopAtWordBoundary,
expected: {
node: expectedNodeSelector,
offset: expectedOffset,
Expand All @@ -152,7 +153,9 @@ describe('DOMTextScanner seek tests', () => {
if (node === null || expectedNode === null) { continue; }

test(`${testDescription} standard test`, () => {
const scanner = new DOMTextScanner(node, offset, forcePreserveWhitespace, generateLayoutContent);
console.log('stopAtWordBoundary', stopAtWordBoundary);

const scanner = new DOMTextScanner(node, offset, forcePreserveWhitespace, generateLayoutContent, stopAtWordBoundary);
scanner.seek(length);

const {node: actualNode1, offset: actualOffset1, content: actualContent1, remainder: actualRemainder1} = scanner;
Expand Down
1 change: 1 addition & 0 deletions types/test/dom-text-scanner.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export type TestData = {
forcePreserveWhitespace?: boolean;
generateLayoutContent?: boolean;
reversible?: boolean;
stopAtWordBoundary?: boolean;
expected: {
node: string;
offset: number;
Expand Down

0 comments on commit 19e7b54

Please sign in to comment.