1
// Copyright 2008 Google Inc. All Rights Reserved.
2
// Redistribution and use in source and binary forms, with or without
3
// modification, are permitted provided that the following conditions are
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.
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.
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);
32
expected = ["a", "b"];
33
result = "ab".split(/a*?/);
34
assertArrayEquals(expected, result, 2);
37
result = "ab".split(/a*/);
38
assertArrayEquals(expected, result, 3);
41
result = "ab".split(/a*?/, 1);
42
assertArrayEquals(expected, result, 4);
45
result = "ab".split(/a*/, 1);
46
assertArrayEquals(expected, result, 5);
48
expected = ["as","fas","fas","f"];
49
result = "asdfasdfasdf".split("d");
50
assertArrayEquals(expected, result, 6);
52
expected = ["as","fas","fas","f"];
53
result = "asdfasdfasdf".split("d", -1);
54
assertArrayEquals(expected, result, 7);
56
expected = ["as", "fas"];
57
result = "asdfasdfasdf".split("d", 2);
58
assertArrayEquals(expected, result, 8);
61
result = "asdfasdfasdf".split("d", 0);
62
assertArrayEquals(expected, result, 9);
64
expected = ["as","fas","fas",""];
65
result = "asdfasdfasd".split("d");
66
assertArrayEquals(expected, result, 10);
69
result = "".split("");
70
assertArrayEquals(expected, result, 11);
73
result = "".split("a");
74
assertArrayEquals(expected, result, 12);
77
result = "axxb".split(/x*/);
78
assertArrayEquals(expected, result, 13);
81
result = "axxb".split(/x+/);
82
assertArrayEquals(expected, result, 14);
84
expected = ["a","","b"]
85
result = "axxb".split(/x/);
86
assertArrayEquals(expected, result, 15);
88
// This was http://b/issue?id=1151354
89
expected = ["div", "#id", ".class"]
90
result = "div#id.class".split(/(?=[#.])/);
91
assertArrayEquals(expected, result, 16);
93
expected = ["div", "#i", "d", ".class"]
94
result = "div#id.class".split(/(?=[d#.])/);
95
assertArrayEquals(expected, result, 17);
97
expected = ["a", "b", "c"]
98
result = "abc".split(/(?=.)/);
99
assertArrayEquals(expected, result, 18);
101
/* "ab".split(/((?=.))/)
109
* Opera seems to have this right. The others make no sense.
111
expected = ["a", "", "b"]
112
result = "ab".split(/((?=.))/);
113
assertArrayEquals(expected, result, 19);
115
/* "ab".split(/(?=)/)
123
expected = ["a", "b"]
124
result = "ab".split(/(?=)/);
125
assertArrayEquals(expected, result, 20);