test/script/basic/JDK-8013131.js

changeset 0
b1a7da25b547
child 962
ac62e33a99b0
equal deleted inserted replaced
-1:000000000000 0:b1a7da25b547
1 /*
2 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /**
25 * JDK-8013131: Various compatibility issues in String.prototype.split()
26 *
27 * @test
28 * @run
29 */
30
31
32 // Make sure limit is honored with undefined/empty separator
33 print(JSON.stringify("aa".split(undefined, 0)));
34 print(JSON.stringify("abc".split("", 1)));
35
36 // Make sure limit is honored with capture groups
37 print(JSON.stringify("aa".split(/(a)/, 1)));
38 print(JSON.stringify("aa".split(/(a)/, 2)));
39 print(JSON.stringify("aa".split(/((a))/, 1)));
40 print(JSON.stringify("aa".split(/((a))/, 2)));
41
42 // Empty capture group at end of string should be ignored
43 print(JSON.stringify("aaa".split(/((?:))/)));
44
45 // Tests below are to make sure that split does not read or write lastIndex property
46 var r = /a/;
47 r.lastIndex = {
48 valueOf: function(){throw 2}
49 };
50 print(JSON.stringify("aa".split(r)));
51
52 r = /a/g;
53 r.lastIndex = 100;
54 print(JSON.stringify("aa".split(r)));
55 print(r.lastIndex);
56
57 r = /((?:))/g;
58 r.lastIndex = 100;
59 print(JSON.stringify("aaa".split(r)));
60 print(r.lastIndex);
61
62 // Make sure lastIndex is not updated on non-global regexp
63 r = /a/;
64 r.lastIndex = 100;
65 print(JSON.stringify(r.exec("aaa")));
66 print(r.lastIndex);

mercurial