1 /*
2 * Copyright (c) 2015, 2017, 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 /* @test
25 * @bug 8058779 8054307
26 * @library /test/lib
27 * @build jdk.test.lib.RandomFactory
28 * @run testng LiteralReplace
29 * @summary Basic tests of String.replace(CharSequence, CharSequence)
30 * @key randomness
31 */
32
33 import java.util.ArrayList;
34 import java.util.Arrays;
35 import java.util.Iterator;
36 import java.util.regex.Matcher;
37 import java.util.regex.Pattern;
38 import java.util.Random;
39
40 import jdk.test.lib.RandomFactory;
41
42 import org.testng.annotations.Test;
43 import org.testng.annotations.DataProvider;
44 import static org.testng.Assert.fail;
45
87 {"abcdefgh", "def", "DEF", "abcDEFgh"},
88 {"abcdefgh", "123", "DEF", "abcdefgh"},
89 {"abcdefgh", "abcdefghi", "DEF", "abcdefgh"},
90 {"abcdefghabc", "abc", "DEF", "DEFdefghDEF"},
91 {"abcdefghdef", "def", "", "abcgh"},
92 {"abcdefgh", "", "_", "_a_b_c_d_e_f_g_h_"},
93 {"", "", "", ""},
94 {"", "a", "b", ""},
95 {"", "", "abc", "abc"},
96 {"abcdefgh", "abcdefgh", "abcdefgh", "abcdefgh"},
97 {"abcdefgh", "abcdefgh", "abcdefghi", "abcdefghi"},
98 {"abcdefgh", "abcdefgh", "", ""},
99 {"abcdabcd", "abcd", "", ""},
100 {"aaaaaaaaa", "aa", "_X_", "_X__X__X__X_a"},
101 {"aaaaaaaaa", "aa", "aaa", "aaaaaaaaaaaaa"},
102 {"aaaaaaaaa", "aa", "aa", "aaaaaaaaa"},
103 {"a.c.e.g.", ".", "-", "a-c-e-g-"},
104 {"abcdefgh", "[a-h]", "X", "abcdefgh"},
105 {"aa+", "a+", "", "a"},
106 {"^abc$", "abc", "x", "^x$"},
107
108 // more with non-latin1 characters
109 {"\u4e00\u4e00\u4e00",
110 "\u4e00\u4e00",
111 "\u4e01",
112 "\u4e01\u4e00"},
113
114 {"\u4e00\u4e01\u4e02\u4e03\u4e04\u4e05\u4e06\u4e07\u4e08",
115 "\u4e03\u4e04\u4e05",
116 "\u4e10\u4e11\u4e12",
117 "\u4e00\u4e01\u4e02\u4e10\u4e11\u4e12\u4e06\u4e07\u4e08"},
118
119 {"\u4e00\u4e01\u4e02\u4e03\u4e04\u4e05\u4e06\u4e07\u4e08",
120 "ABC",
121 "\u4e10\u4e11\u4e12",
122 "\u4e00\u4e01\u4e02\u4e03\u4e04\u4e05\u4e06\u4e07\u4e08"},
123
124 {"\u4e00\u4e01\u4e02\u4e03\u4e04\u4e02\u4e03\u4e07\u4e08",
125 "\u4e02\u4e03",
126 "\u4e12\u4e13",
|
1 /*
2 * Copyright (c) 2015, 2019, 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 /* @test
25 * @bug 8058779 8054307 8222955
26 * @library /test/lib
27 * @build jdk.test.lib.RandomFactory
28 * @run testng LiteralReplace
29 * @summary Basic tests of String.replace(CharSequence, CharSequence)
30 * @key randomness
31 */
32
33 import java.util.ArrayList;
34 import java.util.Arrays;
35 import java.util.Iterator;
36 import java.util.regex.Matcher;
37 import java.util.regex.Pattern;
38 import java.util.Random;
39
40 import jdk.test.lib.RandomFactory;
41
42 import org.testng.annotations.Test;
43 import org.testng.annotations.DataProvider;
44 import static org.testng.Assert.fail;
45
87 {"abcdefgh", "def", "DEF", "abcDEFgh"},
88 {"abcdefgh", "123", "DEF", "abcdefgh"},
89 {"abcdefgh", "abcdefghi", "DEF", "abcdefgh"},
90 {"abcdefghabc", "abc", "DEF", "DEFdefghDEF"},
91 {"abcdefghdef", "def", "", "abcgh"},
92 {"abcdefgh", "", "_", "_a_b_c_d_e_f_g_h_"},
93 {"", "", "", ""},
94 {"", "a", "b", ""},
95 {"", "", "abc", "abc"},
96 {"abcdefgh", "abcdefgh", "abcdefgh", "abcdefgh"},
97 {"abcdefgh", "abcdefgh", "abcdefghi", "abcdefghi"},
98 {"abcdefgh", "abcdefgh", "", ""},
99 {"abcdabcd", "abcd", "", ""},
100 {"aaaaaaaaa", "aa", "_X_", "_X__X__X__X_a"},
101 {"aaaaaaaaa", "aa", "aaa", "aaaaaaaaaaaaa"},
102 {"aaaaaaaaa", "aa", "aa", "aaaaaaaaa"},
103 {"a.c.e.g.", ".", "-", "a-c-e-g-"},
104 {"abcdefgh", "[a-h]", "X", "abcdefgh"},
105 {"aa+", "a+", "", "a"},
106 {"^abc$", "abc", "x", "^x$"},
107 {"abc", "b", "_", "a_c"},
108 {"abc", "bc", "_", "a_"},
109 {"abc".repeat(65537) + "end", "b", "_XYZ_", "a_XYZ_c".repeat(65537) + "end"},
110 {"abc".repeat(65537) + "end", "a", "_", "_bc".repeat(65537) + "end"},
111 {"a".repeat(65537), "a", "", ""},
112 {"ab".repeat(65537), "a", "", "b".repeat(65537)},
113 {"ab".repeat(65537), "ab", "", ""},
114 {"b" + "ab".repeat(65537), "ab", "", "b"},
115
116 // more with non-latin1 characters
117 {"\u4e00\u4e00\u4e00",
118 "\u4e00\u4e00",
119 "\u4e01",
120 "\u4e01\u4e00"},
121
122 {"\u4e00\u4e01\u4e02\u4e03\u4e04\u4e05\u4e06\u4e07\u4e08",
123 "\u4e03\u4e04\u4e05",
124 "\u4e10\u4e11\u4e12",
125 "\u4e00\u4e01\u4e02\u4e10\u4e11\u4e12\u4e06\u4e07\u4e08"},
126
127 {"\u4e00\u4e01\u4e02\u4e03\u4e04\u4e05\u4e06\u4e07\u4e08",
128 "ABC",
129 "\u4e10\u4e11\u4e12",
130 "\u4e00\u4e01\u4e02\u4e03\u4e04\u4e05\u4e06\u4e07\u4e08"},
131
132 {"\u4e00\u4e01\u4e02\u4e03\u4e04\u4e02\u4e03\u4e07\u4e08",
133 "\u4e02\u4e03",
134 "\u4e12\u4e13",
|