|
1 /* |
|
2 * Copyright (c) 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 * @test |
|
26 * @bug 8016846 8024341 |
|
27 * @summary Unit tests for wrapping classes should delegate to default methods |
|
28 * @library ../stream/bootlib |
|
29 * @build java.util.stream.OpTestCase |
|
30 * @run testng/othervm PatternStreamTest |
|
31 */ |
|
32 |
|
33 import org.testng.annotations.DataProvider; |
|
34 import org.testng.annotations.Test; |
|
35 |
|
36 import java.util.ArrayList; |
|
37 import java.util.List; |
|
38 import java.util.function.Supplier; |
|
39 import java.util.regex.Pattern; |
|
40 import java.util.stream.LambdaTestHelpers; |
|
41 import java.util.stream.OpTestCase; |
|
42 import java.util.stream.Stream; |
|
43 import java.util.stream.TestData; |
|
44 |
|
45 @Test |
|
46 public class PatternStreamTest extends OpTestCase { |
|
47 |
|
48 @DataProvider(name = "Stream<String>") |
|
49 public static Object[][] makeStreamTestData() { |
|
50 List<Object[]> data = new ArrayList<>(); |
|
51 |
|
52 String description = ""; |
|
53 String input = "awgqwefg1fefw4vssv1vvv1"; |
|
54 Pattern pattern = Pattern.compile("4"); |
|
55 List<String> expected = new ArrayList<>(); |
|
56 expected.add("awgqwefg1fefw"); |
|
57 expected.add("vssv1vvv1"); |
|
58 |
|
59 // Must match the type signature of the consumer of this data, testStrings |
|
60 // String, String, Pattern, List<String> |
|
61 data.add(new Object[]{description, input, pattern, expected}); |
|
62 |
|
63 input = "afbfq\u00a3abgwgb\u00a3awngnwggw\u00a3a\u00a3ahjrnhneerh"; |
|
64 pattern = Pattern.compile("\u00a3a"); |
|
65 expected = new ArrayList<>(); |
|
66 expected.add("afbfq"); |
|
67 expected.add("bgwgb"); |
|
68 expected.add("wngnwggw"); |
|
69 expected.add(""); |
|
70 expected.add("hjrnhneerh"); |
|
71 |
|
72 data.add(new Object[]{description, input, pattern, expected}); |
|
73 |
|
74 |
|
75 input = "awgqwefg1fefw4vssv1vvv1"; |
|
76 pattern = Pattern.compile("1"); |
|
77 expected = new ArrayList<>(); |
|
78 expected.add("awgqwefg"); |
|
79 expected.add("fefw4vssv"); |
|
80 expected.add("vvv"); |
|
81 |
|
82 data.add(new Object[]{description, input, pattern, expected}); |
|
83 |
|
84 |
|
85 input = "a\u4ebafg1fefw\u4eba4\u9f9cvssv\u9f9c1v\u672c\u672cvv"; |
|
86 pattern = Pattern.compile("1"); |
|
87 expected = new ArrayList<>(); |
|
88 expected.add("a\u4ebafg"); |
|
89 expected.add("fefw\u4eba4\u9f9cvssv\u9f9c"); |
|
90 expected.add("v\u672c\u672cvv"); |
|
91 |
|
92 data.add(new Object[]{description, input, pattern, expected}); |
|
93 |
|
94 |
|
95 input = "1\u56da23\u56da456\u56da7890"; |
|
96 pattern = Pattern.compile("\u56da"); |
|
97 expected = new ArrayList<>(); |
|
98 expected.add("1"); |
|
99 expected.add("23"); |
|
100 expected.add("456"); |
|
101 expected.add("7890"); |
|
102 |
|
103 data.add(new Object[]{description, input, pattern, expected}); |
|
104 |
|
105 |
|
106 input = "1\u56da23\u9f9c\u672c\u672c\u56da456\u56da\u9f9c\u672c7890"; |
|
107 pattern = Pattern.compile("\u56da"); |
|
108 expected = new ArrayList<>(); |
|
109 expected.add("1"); |
|
110 expected.add("23\u9f9c\u672c\u672c"); |
|
111 expected.add("456"); |
|
112 expected.add("\u9f9c\u672c7890"); |
|
113 |
|
114 data.add(new Object[]{description, input, pattern, expected}); |
|
115 |
|
116 |
|
117 input = ""; |
|
118 pattern = Pattern.compile("\u56da"); |
|
119 expected = new ArrayList<>(); |
|
120 |
|
121 data.add(new Object[]{description, input, pattern, expected}); |
|
122 |
|
123 |
|
124 description = "Multiple separators"; |
|
125 input = "This is,testing: with\tdifferent separators."; |
|
126 pattern = Pattern.compile("[ \t,:.]"); |
|
127 expected = new ArrayList<>(); |
|
128 expected.add("This"); |
|
129 expected.add("is"); |
|
130 expected.add("testing"); |
|
131 expected.add(""); |
|
132 expected.add("with"); |
|
133 expected.add("different"); |
|
134 expected.add("separators"); |
|
135 |
|
136 |
|
137 description = "Repeated separators within and at end"; |
|
138 input = "boo:and:foo"; |
|
139 pattern = Pattern.compile("o"); |
|
140 expected = new ArrayList<>(); |
|
141 expected.add("b"); |
|
142 expected.add(""); |
|
143 expected.add(":and:f"); |
|
144 |
|
145 |
|
146 description = "Many repeated separators within and at end"; |
|
147 input = "booooo:and:fooooo"; |
|
148 pattern = Pattern.compile("o"); |
|
149 expected = new ArrayList<>(); |
|
150 expected.add("b"); |
|
151 expected.add(""); |
|
152 expected.add(""); |
|
153 expected.add(""); |
|
154 expected.add(""); |
|
155 expected.add(":and:f"); |
|
156 |
|
157 description = "Many repeated separators before last match"; |
|
158 input = "fooooo:"; |
|
159 pattern = Pattern.compile("o"); |
|
160 expected = new ArrayList<>(); |
|
161 expected.add("f"); |
|
162 expected.add(""); |
|
163 expected.add(""); |
|
164 expected.add(""); |
|
165 expected.add(""); |
|
166 expected.add(":"); |
|
167 |
|
168 data.add(new Object[] {description, input, pattern, expected}); |
|
169 return data.toArray(new Object[0][]); |
|
170 } |
|
171 |
|
172 @Test(dataProvider = "Stream<String>") |
|
173 public void testStrings(String description, String input, Pattern pattern, List<String> expected) { |
|
174 Supplier<Stream<String>> ss = () -> pattern.splitAsStream(input); |
|
175 withData(TestData.Factory.ofSupplier(description, ss)) |
|
176 .stream(LambdaTestHelpers.identity()) |
|
177 .expectedResult(expected) |
|
178 .exercise(); |
|
179 } |
|
180 } |