2 <div id=
"container"></div>
3 <pre id=
"console" style=
"visibility: hidden;"></pre>
7 document
.getElementById("console").appendChild(document
.createTextNode(message
+ "\n"));
10 function testFindString(text
, target
, options
, expectedRanges
)
12 log("Searching for \u2018" + target
+ "\u2019 " + (text
.length
<= 64 ? "in \u2018" + text
+ "\u2019 " : "in long string ") + "with options [" + options
.join(", ") + "]:");
14 var container
= document
.getElementById("container");
15 container
.innerHTML
= text
;
16 document
.body
.offsetTop
;
17 var selection
= getSelection();
21 while (expectedRange
= expectedRanges
.shift()) {
22 var found
= testRunner
.findString(target
, options
);
24 var actualRange
= [selection
.baseOffset
, selection
.extentOffset
];
25 if (expectedRange
[0] !== actualRange
[0] || expectedRange
[1] !== actualRange
[1])
26 log("FAIL: Expected a match at " + expectedRange
+ " but got a match at " + actualRange
+ " instead.");
28 log("PASS: Got a match at " + expectedRange
+ " as expected.");
29 } else if (expectedRange
.length
)
30 log("FAIL: Expected " + expectedRange
+ " but got no match.");
32 log("PASS: Got no match as expected.");
34 container
.innerText
= "";
38 testRunner
.dumpAsText();
40 testFindString("Lorem ipsum dolor sit amet", "o", [], [[1, 2], [13, 14], [15, 16], []]);
41 testFindString("Lorem ipsum dolor sit amet", "o", ["WrapAround"], [[1, 2], [13, 14], [15, 16], [1, 2]]);
42 testFindString("Lorem ipsum dolor sit amet", "o", ["Backwards"], [[15, 16], [13, 14], [1, 2], []]);
43 testFindString("Lorem ipsum dolor sit amet", "o", ["Backwards", "WrapAround"], [[15, 16], [13, 14], [1, 2], [15, 16]]);
44 testFindString("Lorem ipsum dolor sit amet", "O", [], [[]]);
45 testFindString("Lorem ipsum dolor sit amet", "O", ["CaseInsensitive"], [[1, 2], [13, 14], [15, 16]]);
47 testFindString("insurmountable mountain", "mount", [], [[5, 10], [15, 20], []]);
48 testFindString("insurmountable mountain", "mount", ["AtWordStarts"], [[15, 20], []]);
50 testFindString("cocoa", "co", [], [[0, 2], [2, 4], []]);
51 testFindString("cocoa", "co", ["AtWordStarts"], [[0, 2], []]);
53 testFindString("webkit.org", "org", ["AtWordStarts"], [[7, 10]]);
54 testFindString("webkit.org", ".org", ["AtWordStarts"], [[6, 10], []]);
56 testFindString("webkit.org", "rg", ["AtWordStarts", "TreatMedialCapitalAsWordStart"], [[]]);
57 testFindString("webkit.org", "org", ["AtWordStarts", "TreatMedialCapitalAsWordStart"], [[7, 10], []]);
58 testFindString("webkit.org", ".org", ["AtWordStarts", "TreatMedialCapitalAsWordStart"], [[6, 10], []]);
59 testFindString("webkit.org", "t.org", ["AtWordStarts", "TreatMedialCapitalAsWordStart"], [[]]);
61 testFindString("WebKit", "it", ["AtWordStarts", "TreatMedialCapitalAsWordStart"], [[]]);
62 testFindString("WebKit", "Kit", ["AtWordStarts", "TreatMedialCapitalAsWordStart"], [[3, 6], []]);
63 testFindString("WebKit", "bKit", ["AtWordStarts", "TreatMedialCapitalAsWordStart"], [[]]);
65 testFindString("XMLHTTPRequest", "equest", ["AtWordStarts", "TreatMedialCapitalAsWordStart"], [[]]);
66 testFindString("XMLHTTPRequest", "Request", ["AtWordStarts", "TreatMedialCapitalAsWordStart"], [[7, 14], []]);
67 testFindString("XMLHTTPRequest", "PRequest", ["AtWordStarts", "TreatMedialCapitalAsWordStart"], [[]]);
69 testFindString("LP64", "64", ["AtWordStarts"], [[]]);
70 testFindString("LP64", "4", ["AtWordStarts", "TreatMedialCapitalAsWordStart"], [[]]);
71 testFindString("LP64", "64", ["AtWordStarts", "TreatMedialCapitalAsWordStart"], [[2, 4], []]);
72 testFindString("LP64", "P64", ["AtWordStarts", "TreatMedialCapitalAsWordStart"], [[]]);
74 testFindString("\u8d77\u52d5\u6226\u58eb", "\u52d5\u6226\u58eb", ["AtWordStarts"], [[1, 4], []]);
75 testFindString("\u8d77\u52d5\u6226\u58eb", "\u6226\u58eb", ["AtWordStarts"], [[2, 4], []]);
76 testFindString("\u8d77\u52d5\u6226\u58eb", "\u58eb", ["AtWordStarts"], [[3, 4], []]);
78 const searchBufferSize
= 8192;
79 const searchBufferOverlapSize
= searchBufferSize
/ 4;
80 const searchBufferUnoverlappedSize
= searchBufferSize
- searchBufferOverlapSize
;
81 var bufferSizedString
= "X";
82 while (bufferSizedString
.length
< searchBufferSize
)
83 bufferSizedString
+= bufferSizedString
;
84 bufferSizedString
= bufferSizedString
.substring(0, searchBufferSize
);
86 testFindString(bufferSizedString
.substring(0, searchBufferUnoverlappedSize
- 2) + " ba a" + bufferSizedString
, "a", ["AtWordStarts"], [[searchBufferUnoverlappedSize
+ 2, searchBufferUnoverlappedSize
+ 3], []]);
90 "\u0e1b\u0e39\u0e40\u0e25",
92 "\u0e01\u0e0a\u0e01\u0e23", // thaiWords[2] + thaiWords[0]
93 "\u0e01\u0e23\u0e01\u0e0a", // thaiWords[0] + thaiWords[2]
94 "\u0e1a\u0e07\u0e01\u0e0a", // ends with thaiWords[2]
97 testFindString(thaiWords
.join(""), thaiWords
[0], [], [[0, 2], [10, 12], [12, 14], []]);
98 testFindString(thaiWords
.join(""), thaiWords
[0], ["AtWordStarts"], [[0, 2], [12, 14], []]);
100 testFindString(thaiWords
.join(""), thaiWords
[2], [], [[6, 8], [8, 10], [14, 16], [18, 20], []]);
101 testFindString(thaiWords
.join(""), thaiWords
[2], ["AtWordStarts"], [[6, 8], [8, 10], []]);
103 testFindString(bufferSizedString
.substring(0, searchBufferUnoverlappedSize
) + thaiWords
.join("") + bufferSizedString
, thaiWords
[0], [], [[searchBufferUnoverlappedSize
, searchBufferUnoverlappedSize
+ 2], [searchBufferUnoverlappedSize
+ 10, searchBufferUnoverlappedSize
+ 12], [searchBufferUnoverlappedSize
+ 12, searchBufferUnoverlappedSize
+ 14], []]);
104 testFindString(bufferSizedString
.substring(0, searchBufferUnoverlappedSize
) + thaiWords
.join("") + bufferSizedString
, thaiWords
[0], ["AtWordStarts"], [[searchBufferUnoverlappedSize
+ 12, searchBufferUnoverlappedSize
+ 14], []]);
105 testFindString(bufferSizedString
.substring(0, searchBufferUnoverlappedSize
- 1) + " " + thaiWords
.join("") + bufferSizedString
, thaiWords
[0], ["AtWordStarts"], [[searchBufferUnoverlappedSize
, searchBufferUnoverlappedSize
+ 2], [searchBufferUnoverlappedSize
+ 12, searchBufferUnoverlappedSize
+ 14], []]);
106 testFindString(bufferSizedString
.substring(0, searchBufferUnoverlappedSize
- 3) + " " + thaiWords
[4] + bufferSizedString
, thaiWords
[2], ["AtWordStarts"], [[]]);
108 testFindString("Spaces, the final frontier", " ", ["AtWordStarts"], [[7, 8], [11, 12], [17, 18], []]);
109 testFindString("Use an @import rule", "@", ["AtWordStarts"], [[7, 8], []]);
110 testFindString("If ((x + 5) * 2) = 14, then x = 2", "(x", ["AtWordStarts"], [[4, 6], []]);
112 testFindString("hello<img src='../resources/abe.png'>world", "lowo", [], [[3, 2], []]);
114 document
.getElementById("console").style
.removeProperty("visibility");