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 |
11 // with the distribution. | 11 // with the distribution. |
12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
15 // | 15 // |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
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 expected = ["A", undefined, "B", "bold", "/", "B", "and", undefined, "CODE", "co
ded", "/", "CODE", ""]; | 28 expected = ["A", undefined, "B", "bold", "/", "B", "and", undefined, "CODE", "co
ded", "/", "CODE", ""]; |
29 result = "A<B>bold</B>and<CODE>coded</CODE>".split(/<(\/)?([^<>]+)>/); | 29 result = "A<B>bold</B>and<CODE>coded</CODE>".split(/<(\/)?([^<>]+)>/); |
30 assertArrayEquals(expected, result, 1); | 30 assertArrayEquals(expected, result); |
31 | 31 |
32 expected = ["a", "b"]; | |
33 result = "ab".split(/a*?/); | |
34 assertArrayEquals(expected, result, 2); | |
35 | 32 |
36 expected = ["", "b"]; | 33 assertArrayEquals(["a", "b"], "ab".split(/a*?/)); |
37 result = "ab".split(/a*/); | |
38 assertArrayEquals(expected, result, 3); | |
39 | 34 |
40 expected = ["a"]; | 35 assertArrayEquals(["", "b"], "ab".split(/a*/)); |
41 result = "ab".split(/a*?/, 1); | |
42 assertArrayEquals(expected, result, 4); | |
43 | 36 |
44 expected = [""]; | 37 assertArrayEquals(["a"], "ab".split(/a*?/, 1)); |
45 result = "ab".split(/a*/, 1); | |
46 assertArrayEquals(expected, result, 5); | |
47 | 38 |
48 expected = ["as","fas","fas","f"]; | 39 assertArrayEquals([""], "ab".split(/a*/, 1)); |
49 result = "asdfasdfasdf".split("d"); | |
50 assertArrayEquals(expected, result, 6); | |
51 | 40 |
52 expected = ["as","fas","fas","f"]; | 41 assertArrayEquals(["as","fas","fas","f"], "asdfasdfasdf".split("d")); |
53 result = "asdfasdfasdf".split("d", -1); | |
54 assertArrayEquals(expected, result, 7); | |
55 | 42 |
56 expected = ["as", "fas"]; | 43 assertArrayEquals(["as","fas","fas","f"], "asdfasdfasdf".split("d", -1)); |
57 result = "asdfasdfasdf".split("d", 2); | |
58 assertArrayEquals(expected, result, 8); | |
59 | 44 |
60 expected = []; | 45 assertArrayEquals(["as", "fas"], "asdfasdfasdf".split("d", 2)); |
61 result = "asdfasdfasdf".split("d", 0); | |
62 assertArrayEquals(expected, result, 9); | |
63 | 46 |
64 expected = ["as","fas","fas",""]; | 47 assertArrayEquals([], "asdfasdfasdf".split("d", 0)); |
65 result = "asdfasdfasd".split("d"); | |
66 assertArrayEquals(expected, result, 10); | |
67 | 48 |
68 expected = []; | 49 assertArrayEquals(["as","fas","fas",""], "asdfasdfasd".split("d")); |
69 result = "".split(""); | |
70 assertArrayEquals(expected, result, 11); | |
71 | 50 |
72 expected = [""] | 51 assertArrayEquals([], "".split("")); |
73 result = "".split("a"); | |
74 assertArrayEquals(expected, result, 12); | |
75 | 52 |
76 expected = ["a","b"] | 53 assertArrayEquals([""], "".split("a")); |
77 result = "axxb".split(/x*/); | |
78 assertArrayEquals(expected, result, 13); | |
79 | 54 |
80 expected = ["a","b"] | 55 assertArrayEquals(["a","b"], "axxb".split(/x*/)); |
81 result = "axxb".split(/x+/); | |
82 assertArrayEquals(expected, result, 14); | |
83 | 56 |
84 expected = ["a","","b"] | 57 assertArrayEquals(["a","b"], "axxb".split(/x+/)); |
85 result = "axxb".split(/x/); | 58 |
86 assertArrayEquals(expected, result, 15); | 59 assertArrayEquals(["a","","b"], "axxb".split(/x/)); |
87 | 60 |
88 // This was http://b/issue?id=1151354 | 61 // This was http://b/issue?id=1151354 |
89 expected = ["div", "#id", ".class"] | 62 assertArrayEquals(["div", "#id", ".class"], "div#id.class".split(/(?=[#.])/)); |
90 result = "div#id.class".split(/(?=[#.])/); | |
91 assertArrayEquals(expected, result, 16); | |
92 | 63 |
93 expected = ["div", "#i", "d", ".class"] | |
94 result = "div#id.class".split(/(?=[d#.])/); | |
95 assertArrayEquals(expected, result, 17); | |
96 | 64 |
97 expected = ["a", "b", "c"] | 65 assertArrayEquals(["div", "#i", "d", ".class"], "div#id.class".split(/(?=[d#.])/
)); |
98 result = "abc".split(/(?=.)/); | 66 |
99 assertArrayEquals(expected, result, 18); | 67 assertArrayEquals(["a", "b", "c"], "abc".split(/(?=.)/)); |
| 68 |
100 | 69 |
101 /* "ab".split(/((?=.))/) | 70 /* "ab".split(/((?=.))/) |
102 * | 71 * |
103 * KJS: ,a,,b | 72 * KJS: ,a,,b |
104 * SM: a,,b, | 73 * SM: a,,b, |
105 * IE: a,b | 74 * IE: a,b |
106 * Opera: a,,b | 75 * Opera: a,,b |
107 * V8: a,,b | 76 * V8: a,,b |
108 * | 77 * |
109 * Opera seems to have this right. The others make no sense. | 78 * Opera seems to have this right. The others make no sense. |
110 */ | 79 */ |
111 expected = ["a", "", "b"] | 80 assertArrayEquals(["a", "", "b"], "ab".split(/((?=.))/)); |
112 result = "ab".split(/((?=.))/); | |
113 assertArrayEquals(expected, result, 19); | |
114 | 81 |
115 /* "ab".split(/(?=)/) | 82 /* "ab".split(/(?=)/) |
116 * | 83 * |
117 * KJS: a,b | 84 * KJS: a,b |
118 * SM: ab | 85 * SM: ab |
119 * IE: a,b | 86 * IE: a,b |
120 * Opera: a,b | 87 * Opera: a,bb |
121 * V8: a,b | 88 * V8: a,b |
122 */ | 89 */ |
123 expected = ["a", "b"] | 90 assertArrayEquals(["a", "b"], "ab".split(/(?=)/)); |
124 result = "ab".split(/(?=)/); | |
125 assertArrayEquals(expected, result, 20); | |
126 | 91 |
| 92 |
| 93 // For issue http://code.google.com/p/v8/issues/detail?id=924 |
| 94 // Splitting the empty string is a special case. |
| 95 assertEquals([""], ''.split()); |
| 96 assertEquals([""], ''.split(/./)); |
| 97 assertEquals([], ''.split(/.?/)); |
| 98 assertEquals([], ''.split(/.??/)); |
| 99 assertEquals([], ''.split(/()()/)); |
OLD | NEW |