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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 assertEquals(1, twoByteString.indexOf("\u0391\u03a3"), "Alpha Sigma"); | 70 assertEquals(1, twoByteString.indexOf("\u0391\u03a3"), "Alpha Sigma"); |
71 assertEquals(2, twoByteString.indexOf("\u03a3\u03a3"), "Sigma Sigma"); | 71 assertEquals(2, twoByteString.indexOf("\u03a3\u03a3"), "Sigma Sigma"); |
72 assertEquals(3, twoByteString.indexOf("\u03a3\u0395"), "Sigma Epsilon"); | 72 assertEquals(3, twoByteString.indexOf("\u03a3\u0395"), "Sigma Epsilon"); |
73 | 73 |
74 assertEquals(-1, twoByteString.indexOf("\u0391\u03a3\u0395"), | 74 assertEquals(-1, twoByteString.indexOf("\u0391\u03a3\u0395"), |
75 "Not Alpha Sigma Epsilon"); | 75 "Not Alpha Sigma Epsilon"); |
76 | 76 |
77 //single char pattern | 77 //single char pattern |
78 assertEquals(4, twoByteString.indexOf("\u0395")); | 78 assertEquals(4, twoByteString.indexOf("\u0395")); |
79 | 79 |
| 80 // test string with alignment traps |
| 81 var alignmentString = "\u1122\u2211\u2222\uFF00\u00FF\u00FF"; |
| 82 assertEquals(2, alignmentString.indexOf("\u2222")); |
| 83 assertEquals(4, alignmentString.indexOf("\u00FF\u00FF")); |
| 84 |
| 85 var longAlignmentString = "\uFF00" + "\u00FF".repeat(10); |
| 86 assertEquals(1, |
| 87 longAlignmentString.indexOf("\u00FF".repeat(10))); |
| 88 |
80 // Test complex string indexOf algorithms. Only trigger for long strings. | 89 // Test complex string indexOf algorithms. Only trigger for long strings. |
81 | 90 |
82 // Long string that isn't a simple repeat of a shorter string. | 91 // Long string that isn't a simple repeat of a shorter string. |
83 var long = "A"; | 92 var long = "A"; |
84 for(var i = 66; i < 76; i++) { // from 'B' to 'K' | 93 for(var i = 66; i < 76; i++) { // from 'B' to 'K' |
85 long = long + String.fromCharCode(i) + long; | 94 long = long + String.fromCharCode(i) + long; |
86 } | 95 } |
87 | 96 |
88 // pattern of 15 chars, repeated every 16 chars in long | 97 // pattern of 15 chars, repeated every 16 chars in long |
89 var pattern = "ABACABADABACABA"; | 98 var pattern = "ABACABADABACABA"; |
(...skipping 26 matching lines...) Expand all Loading... |
116 var lengths = [1, 4, 15]; // Single char, simple and complex. | 125 var lengths = [1, 4, 15]; // Single char, simple and complex. |
117 var indices = [0x5, 0x65, 0x85, 0x105, 0x205, 0x285, 0x2005, 0x2085, 0xfff0]; | 126 var indices = [0x5, 0x65, 0x85, 0x105, 0x205, 0x285, 0x2005, 0x2085, 0xfff0]; |
118 for (var lengthIndex = 0; lengthIndex < lengths.length; lengthIndex++) { | 127 for (var lengthIndex = 0; lengthIndex < lengths.length; lengthIndex++) { |
119 var length = lengths[lengthIndex]; | 128 var length = lengths[lengthIndex]; |
120 for (var i = 0; i < indices.length; i++) { | 129 for (var i = 0; i < indices.length; i++) { |
121 var index = indices[i]; | 130 var index = indices[i]; |
122 var pattern = allCharsString.substring(index, index + length); | 131 var pattern = allCharsString.substring(index, index + length); |
123 assertEquals(index, allCharsString.indexOf(pattern)); | 132 assertEquals(index, allCharsString.indexOf(pattern)); |
124 } | 133 } |
125 } | 134 } |
OLD | NEW |