ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1 | // Copyright 2008 the V8 project authors. All rights reserved. |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 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. |
| 27 | |
| 28 | expected = ["A", undefined, "B", "bold", "/", "B", "and", undefined, "CODE", "coded", "/", "CODE", ""]; |
| 29 | result = "A<B>bold</B>and<CODE>coded</CODE>".split(/<(\/)?([^<>]+)>/); |
| 30 | assertArrayEquals(expected, result, 1); |
| 31 | |
| 32 | expected = ["a", "b"]; |
| 33 | result = "ab".split(/a*?/); |
| 34 | assertArrayEquals(expected, result, 2); |
| 35 | |
| 36 | expected = ["", "b"]; |
| 37 | result = "ab".split(/a*/); |
| 38 | assertArrayEquals(expected, result, 3); |
| 39 | |
| 40 | expected = ["a"]; |
| 41 | result = "ab".split(/a*?/, 1); |
| 42 | assertArrayEquals(expected, result, 4); |
| 43 | |
| 44 | expected = [""]; |
| 45 | result = "ab".split(/a*/, 1); |
| 46 | assertArrayEquals(expected, result, 5); |
| 47 | |
| 48 | expected = ["as","fas","fas","f"]; |
| 49 | result = "asdfasdfasdf".split("d"); |
| 50 | assertArrayEquals(expected, result, 6); |
| 51 | |
| 52 | expected = ["as","fas","fas","f"]; |
| 53 | result = "asdfasdfasdf".split("d", -1); |
| 54 | assertArrayEquals(expected, result, 7); |
| 55 | |
| 56 | expected = ["as", "fas"]; |
| 57 | result = "asdfasdfasdf".split("d", 2); |
| 58 | assertArrayEquals(expected, result, 8); |
| 59 | |
| 60 | expected = []; |
| 61 | result = "asdfasdfasdf".split("d", 0); |
| 62 | assertArrayEquals(expected, result, 9); |
| 63 | |
| 64 | expected = ["as","fas","fas",""]; |
| 65 | result = "asdfasdfasd".split("d"); |
| 66 | assertArrayEquals(expected, result, 10); |
| 67 | |
| 68 | expected = []; |
| 69 | result = "".split(""); |
| 70 | assertArrayEquals(expected, result, 11); |
| 71 | |
| 72 | expected = [""] |
| 73 | result = "".split("a"); |
| 74 | assertArrayEquals(expected, result, 12); |
| 75 | |
| 76 | expected = ["a","b"] |
| 77 | result = "axxb".split(/x*/); |
| 78 | assertArrayEquals(expected, result, 13); |
| 79 | |
| 80 | expected = ["a","b"] |
| 81 | result = "axxb".split(/x+/); |
| 82 | assertArrayEquals(expected, result, 14); |
| 83 | |
| 84 | expected = ["a","","b"] |
| 85 | result = "axxb".split(/x/); |
| 86 | assertArrayEquals(expected, result, 15); |
| 87 | |
| 88 | // This was http://b/issue?id=1151354 |
| 89 | expected = ["div", "#id", ".class"] |
| 90 | result = "div#id.class".split(/(?=[#.])/); |
| 91 | assertArrayEquals(expected, result, 16); |
| 92 | |
| 93 | expected = ["div", "#i", "d", ".class"] |
| 94 | result = "div#id.class".split(/(?=[d#.])/); |
| 95 | assertArrayEquals(expected, result, 17); |
| 96 | |
| 97 | expected = ["a", "b", "c"] |
| 98 | result = "abc".split(/(?=.)/); |
| 99 | assertArrayEquals(expected, result, 18); |
| 100 | |
| 101 | /* "ab".split(/((?=.))/) |
| 102 | * |
| 103 | * KJS: ,a,,b |
| 104 | * SM: a,,b, |
| 105 | * IE: a,b |
| 106 | * Opera: a,,b |
| 107 | * V8: a,,b |
| 108 | * |
| 109 | * Opera seems to have this right. The others make no sense. |
| 110 | */ |
| 111 | expected = ["a", "", "b"] |
| 112 | result = "ab".split(/((?=.))/); |
| 113 | assertArrayEquals(expected, result, 19); |
| 114 | |
| 115 | /* "ab".split(/(?=)/) |
| 116 | * |
| 117 | * KJS: a,b |
| 118 | * SM: ab |
| 119 | * IE: a,b |
| 120 | * Opera: a,b |
| 121 | * V8: a,b |
| 122 | */ |
| 123 | expected = ["a", "b"] |
| 124 | result = "ab".split(/(?=)/); |
| 125 | assertArrayEquals(expected, result, 20); |
| 126 | |