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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 | 50 |
51 assertEquals(893, lipsum.indexOf("lorem ipsum, quia dolor sit, amet"), | 51 assertEquals(893, lipsum.indexOf("lorem ipsum, quia dolor sit, amet"), |
52 "Lipsum"); | 52 "Lipsum"); |
53 // test a lot of substrings of differing length and start-position. | 53 // test a lot of substrings of differing length and start-position. |
54 for(var i = 0; i < lipsum.length; i += 3) { | 54 for(var i = 0; i < lipsum.length; i += 3) { |
55 for(var len = 1; i + len < lipsum.length; len += 7) { | 55 for(var len = 1; i + len < lipsum.length; len += 7) { |
56 var substring = lipsum.substring(i, i + len); | 56 var substring = lipsum.substring(i, i + len); |
57 var index = -1; | 57 var index = -1; |
58 do { | 58 do { |
59 index = lipsum.indexOf(substring, index + 1); | 59 index = lipsum.indexOf(substring, index + 1); |
60 assertTrue(index != -1, | 60 assertTrue(index != -1, |
61 "Lipsum substring " + i + ".." + (i + len-1) + " not found"); | 61 "Lipsum substring " + i + ".." + (i + len-1) + " not found"); |
62 assertEquals(lipsum.substring(index, index + len), substring, | 62 assertEquals(lipsum.substring(index, index + len), substring, |
63 "Wrong lipsum substring found: " + i + ".." + (i + len - 1) + "/" + | 63 "Wrong lipsum substring found: " + i + ".." + (i + len - 1) + "/" + |
64 index + ".." + (index + len - 1)); | 64 index + ".." + (index + len - 1)); |
65 } while (index >= 0 && index < i); | 65 } while (index >= 0 && index < i); |
66 assertEquals(i, index, "Lipsum match at " + i + ".." + (i + len - 1)); | 66 assertEquals(i, index, "Lipsum match at " + i + ".." + (i + len - 1)); |
67 } | 67 } |
68 } | 68 } |
OLD | NEW |