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 | |
89 // Test complex string indexOf algorithms. Only trigger for long strings. | 80 // Test complex string indexOf algorithms. Only trigger for long strings. |
90 | 81 |
91 // Long string that isn't a simple repeat of a shorter string. | 82 // Long string that isn't a simple repeat of a shorter string. |
92 var long = "A"; | 83 var long = "A"; |
93 for(var i = 66; i < 76; i++) { // from 'B' to 'K' | 84 for(var i = 66; i < 76; i++) { // from 'B' to 'K' |
94 long = long + String.fromCharCode(i) + long; | 85 long = long + String.fromCharCode(i) + long; |
95 } | 86 } |
96 | 87 |
97 // pattern of 15 chars, repeated every 16 chars in long | 88 // pattern of 15 chars, repeated every 16 chars in long |
98 var pattern = "ABACABADABACABA"; | 89 var pattern = "ABACABADABACABA"; |
(...skipping 26 matching lines...) Expand all Loading... |
125 var lengths = [1, 4, 15]; // Single char, simple and complex. | 116 var lengths = [1, 4, 15]; // Single char, simple and complex. |
126 var indices = [0x5, 0x65, 0x85, 0x105, 0x205, 0x285, 0x2005, 0x2085, 0xfff0]; | 117 var indices = [0x5, 0x65, 0x85, 0x105, 0x205, 0x285, 0x2005, 0x2085, 0xfff0]; |
127 for (var lengthIndex = 0; lengthIndex < lengths.length; lengthIndex++) { | 118 for (var lengthIndex = 0; lengthIndex < lengths.length; lengthIndex++) { |
128 var length = lengths[lengthIndex]; | 119 var length = lengths[lengthIndex]; |
129 for (var i = 0; i < indices.length; i++) { | 120 for (var i = 0; i < indices.length; i++) { |
130 var index = indices[i]; | 121 var index = indices[i]; |
131 var pattern = allCharsString.substring(index, index + length); | 122 var pattern = allCharsString.substring(index, index + length); |
132 assertEquals(index, allCharsString.indexOf(pattern)); | 123 assertEquals(index, allCharsString.indexOf(pattern)); |
133 } | 124 } |
134 } | 125 } |
OLD | NEW |