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

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

Issue 2593593002: [builtins] Fix String.prototype.indexOf with negative positions (Closed)
Patch Set: Created 3 years, 12 months 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 | « src/builtins/builtins-string.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 12 matching lines...) Expand all
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 var s = "test test test"; 28 var s = "test test test";
29 29
30 assertEquals(0, s.indexOf("t")); 30 assertEquals(0, s.indexOf("t"));
31 assertEquals(3, s.indexOf("t", 1)); 31 assertEquals(3, s.indexOf("t", 1));
32 assertEquals(5, s.indexOf("t", 4)); 32 assertEquals(5, s.indexOf("t", 4));
33 assertEquals(5, s.indexOf("t", 4.1));
34 assertEquals(0, s.indexOf("t", 0));
35 assertEquals(0, s.indexOf("t", -1));
36 assertEquals(0, s.indexOf("t", -1));
37 assertEquals(0, s.indexOf("t", -1.1));
38 assertEquals(0, s.indexOf("t", -1073741825));
33 assertEquals(1, s.indexOf("e")); 39 assertEquals(1, s.indexOf("e"));
34 assertEquals(2, s.indexOf("s")); 40 assertEquals(2, s.indexOf("s"));
35 41
36 assertEquals(5, s.indexOf("test", 4)); 42 assertEquals(5, s.indexOf("test", 4));
37 assertEquals(5, s.indexOf("test", 5)); 43 assertEquals(5, s.indexOf("test", 5));
38 assertEquals(10, s.indexOf("test", 6)); 44 assertEquals(10, s.indexOf("test", 6));
45 assertEquals(10, s.indexOf("test", 6.0));
39 assertEquals(0, s.indexOf("test", 0)); 46 assertEquals(0, s.indexOf("test", 0));
47 assertEquals(0, s.indexOf("test", 0.0));
40 assertEquals(0, s.indexOf("test", -1)); 48 assertEquals(0, s.indexOf("test", -1));
49 assertEquals(-1, s.indexOf("not found", -1));
50 assertEquals(0, s.indexOf("test", -1.0));
51 assertEquals(0, s.indexOf("test", -1073741825));
41 assertEquals(0, s.indexOf("test")); 52 assertEquals(0, s.indexOf("test"));
42 assertEquals(-1, s.indexOf("notpresent")); 53 assertEquals(-1, s.indexOf("notpresent"));
43 assertEquals(-1, s.indexOf()); 54 assertEquals(-1, s.indexOf());
44 55
45 for (var i = 0; i < s.length+10; i++) { 56 for (var i = 0; i < s.length+10; i++) {
46 var expected = i < s.length ? i : s.length; 57 var expected = i < s.length ? i : s.length;
47 assertEquals(expected, s.indexOf("", i)); 58 assertEquals(expected, s.indexOf("", i));
48 } 59 }
49 60
50 var reString = "asdf[a-z]+(asdf)?"; 61 var reString = "asdf[a-z]+(asdf)?";
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 })(); 198 })();
188 199
189 (function nonStringPosition() { 200 (function nonStringPosition() {
190 assertEquals(0, "aba".indexOf("a", false)); 201 assertEquals(0, "aba".indexOf("a", false));
191 assertEquals(2, "aba".indexOf("a", true)); 202 assertEquals(2, "aba".indexOf("a", true));
192 assertEquals(2, "aba".indexOf("a", "1")); 203 assertEquals(2, "aba".indexOf("a", "1"));
193 assertEquals(2, "aba".indexOf("a", "1.00000")); 204 assertEquals(2, "aba".indexOf("a", "1.00000"));
194 assertEquals(2, "aba".indexOf("a", "2.00000")); 205 assertEquals(2, "aba".indexOf("a", "2.00000"));
195 assertEquals(-1, "aba".indexOf("a", "3.00000")); 206 assertEquals(-1, "aba".indexOf("a", "3.00000"));
196 })(); 207 })();
OLDNEW
« no previous file with comments | « src/builtins/builtins-string.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698