Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(399)

Side by Side Diff: test/mjsunit/string-indexof-1.js

Issue 2539093002: [runtime] Port simple String.prototype.indexOf cases to TF Builtin (Closed)
Patch Set: merging with master Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/cctest/test-strings.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 var lengths = [1, 4, 15]; // Single char, simple and complex. 130 var lengths = [1, 4, 15]; // Single char, simple and complex.
131 var indices = [0x5, 0x65, 0x85, 0x105, 0x205, 0x285, 0x2005, 0x2085, 0xfff0]; 131 var indices = [0x5, 0x65, 0x85, 0x105, 0x205, 0x285, 0x2005, 0x2085, 0xfff0];
132 for (var lengthIndex = 0; lengthIndex < lengths.length; lengthIndex++) { 132 for (var lengthIndex = 0; lengthIndex < lengths.length; lengthIndex++) {
133 var length = lengths[lengthIndex]; 133 var length = lengths[lengthIndex];
134 for (var i = 0; i < indices.length; i++) { 134 for (var i = 0; i < indices.length; i++) {
135 var index = indices[i]; 135 var index = indices[i];
136 var pattern = allCharsString.substring(index, index + length); 136 var pattern = allCharsString.substring(index, index + length);
137 assertEquals(index, allCharsString.indexOf(pattern)); 137 assertEquals(index, allCharsString.indexOf(pattern));
138 } 138 }
139 } 139 }
140
141 (function nonStringReceivers() {
142 let indexOf = String.prototype.indexOf;
143 assertThrows(() => indexOf.call(null), TypeError);
144 assertThrows(() => indexOf.call(undefined), TypeError);
145
146 assertEquals(-1, indexOf.call(1));
147 assertEquals(0, indexOf.call(1, "1"));
148
149 assertEquals(-1, indexOf.call(1.2));
150 assertEquals(0, indexOf.call(1.2, "1"));
151 assertEquals(1, indexOf.call(1.2, "."));
152 assertEquals(2, indexOf.call(1.2, "2"));
153 assertEquals(-1, indexOf.call(1.2, "1", 2));
154
155 assertEquals(-1, indexOf.call({}));
156 assertEquals(0, indexOf.call({}, "[object Object]"));
157 assertEquals(-1, indexOf.call({}, "[object", 1));
158
159 assertEquals(-1, indexOf.call([]));
160 assertEquals(0, indexOf.call([1,2], "1,2"));
161
162 assertEquals(-1, indexOf.call(this));
163 })();
164
165 (function nonStringSearchString() {
166
167 assertEquals(-1, "".indexOf(1));
168 assertEquals(2, "_0123".indexOf(1));
169
170 assertEquals(-1, "".indexOf(1.2));
171 assertEquals(1, "01.2".indexOf(1.2));
172 assertEquals(1, "01.2".indexOf(1.2, 1));
173 assertEquals(-1, "01.2".indexOf(1.2, 2));
174
175 assertEquals(-1, "".indexOf(null));
176 assertEquals(0, "null".indexOf(null));
177
178 assertEquals(-1, "".indexOf(undefined));
179 assertEquals(1, "_undefined_".indexOf(undefined));
180
181 assertEquals(0, "".indexOf([]));
182 assertEquals(0, "123".indexOf([]));
183 assertEquals(2, "1,2,3".indexOf([2,3]));
184
185 assertEquals(-1, "".indexOf({}));
186 assertEquals(-1, "".indexOf(this));
187 })();
188
189 (function nonStringPosition() {
190 assertEquals(0, "aba".indexOf("a", false));
191 assertEquals(2, "aba".indexOf("a", true));
192 assertEquals(2, "aba".indexOf("a", "1"));
193 assertEquals(2, "aba".indexOf("a", "1.00000"));
194 assertEquals(2, "aba".indexOf("a", "2.00000"));
195 assertEquals(-1, "aba".indexOf("a", "3.00000"));
196 })();
OLDNEW
« no previous file with comments | « test/cctest/test-strings.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698