OLD | NEW |
1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 for(var i = 0; i < long.length - pattern.length; i+= 7) { | 90 for(var i = 0; i < long.length - pattern.length; i+= 7) { |
91 var index = long.indexOf(pattern, i); | 91 var index = long.indexOf(pattern, i); |
92 assertEquals((i + 15) & ~0xf, index, "Long ABACABA...-string at index " + i); | 92 assertEquals((i + 15) & ~0xf, index, "Long ABACABA...-string at index " + i); |
93 } | 93 } |
94 assertEquals(510, long.indexOf("AJABACA"), "Long AJABACA, First J"); | 94 assertEquals(510, long.indexOf("AJABACA"), "Long AJABACA, First J"); |
95 assertEquals(1534, long.indexOf("AJABACA", 511), "Long AJABACA, Second J"); | 95 assertEquals(1534, long.indexOf("AJABACA", 511), "Long AJABACA, Second J"); |
96 | 96 |
97 pattern = "JABACABADABACABA"; | 97 pattern = "JABACABADABACABA"; |
98 assertEquals(511, long.indexOf(pattern), "Long JABACABA..., First J"); | 98 assertEquals(511, long.indexOf(pattern), "Long JABACABA..., First J"); |
99 assertEquals(1535, long.indexOf(pattern, 512), "Long JABACABA..., Second J"); | 99 assertEquals(1535, long.indexOf(pattern, 512), "Long JABACABA..., Second J"); |
| 100 |
| 101 |
| 102 // Search for a non-ASCII string in a pure ASCII string. |
| 103 var asciiString = "arglebargleglopglyfarglebargleglopglyfarglebargleglopglyf"; |
| 104 assertEquals(-1, asciiString.indexOf("\x2061")); |
| 105 |
| 106 |
| 107 // Search in string containing many non-ASCII chars. |
| 108 var allCodePoints = []; |
| 109 for (var i = 0; i < 65536; i++) allCodePoints[i] = i; |
| 110 var allCharsString = String.fromCharCode.apply(String, allCodePoints); |
| 111 // Search for string long enough to trigger complex search with ASCII pattern |
| 112 // and UC16 subject. |
| 113 assertEquals(-1, allCharsString.indexOf("notfound")); |
| 114 |
| 115 // Find substrings. |
| 116 var lengths = [1, 4, 15]; // Single char, simple and complex. |
| 117 var indices = [0x5, 0x65, 0x85, 0x105, 0x205, 0x285, 0x2005, 0x2085, 0xfff0]; |
| 118 for (var lengthIndex = 0; lengthIndex < lengths.length; lengthIndex++) { |
| 119 var length = lengths[lengthIndex]; |
| 120 for (var i = 0; i < indices.length; i++) { |
| 121 var index = indices[i]; |
| 122 var pattern = allCharsString.substring(index, index + length); |
| 123 assertEquals(index, allCharsString.indexOf(pattern)); |
| 124 } |
| 125 } |
OLD | NEW |