1 /*
2 * Copyright (c) 1999, 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 /**
25 * @test
26 * @summary tests RegExp framework (use -Dseed=X to set PRNG seed)
27 * @author Mike McCloskey
28 * @bug 4481568 4482696 4495089 4504687 4527731 4599621 4631553 4619345
29 * 4630911 4672616 4711773 4727935 4750573 4792284 4803197 4757029 4808962
30 * 4872664 4803179 4892980 4900747 4945394 4938995 4979006 4994840 4997476
31 * 5013885 5003322 4988891 5098443 5110268 6173522 4829857 5027748 6376940
32 * 6358731 6178785 6284152 6231989 6497148 6486934 6233084 6504326 6635133
33 * 6350801 6676425 6878475 6919132 6931676 6948903 6990617 7014645 7039066
34 * 7067045 7014640 7189363 8007395 8013252 8013254 8012646 8023647 6559590
35 * 8027645 8035076 8039124 8035975 8074678 6854417 8143854 8147531 7071819
36 * 8151481 4867170 7080302 6728861 6995635 6736245 4916384 6328855 6192895
37 * 6345469 6988218 6693451 7006761 8140212 8143282 8158482 8176029 8184706
38 *
39 * @library /test/lib
40 * @build jdk.test.lib.RandomFactory
41 * @run main RegExTest
42 * @key randomness
43 */
44
45 import java.util.function.Function;
46 import java.util.regex.*;
47 import java.util.Random;
48 import java.util.Scanner;
49 import java.io.*;
50 import java.nio.file.*;
51 import java.util.*;
52 import java.nio.CharBuffer;
53 import java.util.function.Predicate;
54 import jdk.test.lib.RandomFactory;
55
56 /**
57 * This is a test class created to check the operation of
1350 check(p, "1 word word word 2", true);
1351 check(p, "1 wor wo w 2", true);
1352 check(p, "1 word word 2", true);
1353 check(p, "1 word 2", true);
1354 check(p, "1 wo w w 2", true);
1355 check(p, "1 wo w 2", true);
1356 check(p, "1 wor w 2", true);
1357
1358 p = Pattern.compile("([a-z])+?c");
1359 Matcher m = p.matcher("ababcdefdec");
1360 check(m, "ababc");
1361
1362 // Supplementary character test
1363 p = Pattern.compile(toSupplementaries("([a-z])+?c"));
1364 m = p.matcher(toSupplementaries("ababcdefdec"));
1365 check(m, toSupplementaries("ababc"));
1366
1367 report("Reluctant Repetition");
1368 }
1369
1370 private static void serializeTest() throws Exception {
1371 String patternStr = "(b)";
1372 String matchStr = "b";
1373 Pattern pattern = Pattern.compile(patternStr);
1374 ByteArrayOutputStream baos = new ByteArrayOutputStream();
1375 ObjectOutputStream oos = new ObjectOutputStream(baos);
1376 oos.writeObject(pattern);
1377 oos.close();
1378 ObjectInputStream ois = new ObjectInputStream(
1379 new ByteArrayInputStream(baos.toByteArray()));
1380 Pattern serializedPattern = (Pattern)ois.readObject();
1381 ois.close();
1382 Matcher matcher = serializedPattern.matcher(matchStr);
1383 if (!matcher.matches())
1384 failCount++;
1385 if (matcher.groupCount() != 1)
1386 failCount++;
1387
1388 report("Serialization");
1389 }
1390
1391 private static void gTest() {
1392 Pattern pattern = Pattern.compile("\\G\\w");
1393 Matcher matcher = pattern.matcher("abc#x#x");
1394 matcher.find();
1395 matcher.find();
1396 matcher.find();
1397 if (matcher.find())
1398 failCount++;
1399
1400 pattern = Pattern.compile("\\GA*");
1401 matcher = pattern.matcher("1A2AA3");
1402 matcher.find();
1403 if (matcher.find())
1404 failCount++;
1405
1406 pattern = Pattern.compile("\\GA*");
1407 matcher = pattern.matcher("1A2AA3");
|
1 /*
2 * Copyright (c) 1999, 2018, 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 * @summary tests RegExp framework (use -Dseed=X to set PRNG seed)
27 * @author Mike McCloskey
28 * @bug 4481568 4482696 4495089 4504687 4527731 4599621 4631553 4619345
29 * 4630911 4672616 4711773 4727935 4750573 4792284 4803197 4757029 4808962
30 * 4872664 4803179 4892980 4900747 4945394 4938995 4979006 4994840 4997476
31 * 5013885 5003322 4988891 5098443 5110268 6173522 4829857 5027748 6376940
32 * 6358731 6178785 6284152 6231989 6497148 6486934 6233084 6504326 6635133
33 * 6350801 6676425 6878475 6919132 6931676 6948903 6990617 7014645 7039066
34 * 7067045 7014640 7189363 8007395 8013252 8013254 8012646 8023647 6559590
35 * 8027645 8035076 8039124 8035975 8074678 6854417 8143854 8147531 7071819
36 * 8151481 4867170 7080302 6728861 6995635 6736245 4916384 6328855 6192895
37 * 6345469 6988218 6693451 7006761 8140212 8143282 8158482 8176029 8184706
38 * 8194667
39 *
40 * @library /test/lib
41 * @build jdk.test.lib.RandomFactory
42 * @run main RegExTest
43 * @key randomness
44 */
45
46 import java.util.function.Function;
47 import java.util.regex.*;
48 import java.util.Random;
49 import java.util.Scanner;
50 import java.io.*;
51 import java.nio.file.*;
52 import java.util.*;
53 import java.nio.CharBuffer;
54 import java.util.function.Predicate;
55 import jdk.test.lib.RandomFactory;
56
57 /**
58 * This is a test class created to check the operation of
1351 check(p, "1 word word word 2", true);
1352 check(p, "1 wor wo w 2", true);
1353 check(p, "1 word word 2", true);
1354 check(p, "1 word 2", true);
1355 check(p, "1 wo w w 2", true);
1356 check(p, "1 wo w 2", true);
1357 check(p, "1 wor w 2", true);
1358
1359 p = Pattern.compile("([a-z])+?c");
1360 Matcher m = p.matcher("ababcdefdec");
1361 check(m, "ababc");
1362
1363 // Supplementary character test
1364 p = Pattern.compile(toSupplementaries("([a-z])+?c"));
1365 m = p.matcher(toSupplementaries("ababcdefdec"));
1366 check(m, toSupplementaries("ababc"));
1367
1368 report("Reluctant Repetition");
1369 }
1370
1371 private static Pattern serializedPattern(Pattern p) throws Exception {
1372 ByteArrayOutputStream baos = new ByteArrayOutputStream();
1373 ObjectOutputStream oos = new ObjectOutputStream(baos);
1374 oos.writeObject(p);
1375 oos.close();
1376 try (ObjectInputStream ois = new ObjectInputStream(
1377 new ByteArrayInputStream(baos.toByteArray()))) {
1378 return (Pattern)ois.readObject();
1379 }
1380 }
1381
1382 private static void serializeTest() throws Exception {
1383 String patternStr = "(b)";
1384 String matchStr = "b";
1385 Pattern pattern = Pattern.compile(patternStr);
1386 Pattern serializedPattern = serializedPattern(pattern);
1387 Matcher matcher = serializedPattern.matcher(matchStr);
1388 if (!matcher.matches())
1389 failCount++;
1390 if (matcher.groupCount() != 1)
1391 failCount++;
1392
1393 pattern = Pattern.compile("a(?-i)b", Pattern.CASE_INSENSITIVE);
1394 serializedPattern = serializedPattern(pattern);
1395 if (!serializedPattern.matcher("Ab").matches())
1396 failCount++;
1397 if (serializedPattern.matcher("AB").matches())
1398 failCount++;
1399
1400 report("Serialization");
1401 }
1402
1403 private static void gTest() {
1404 Pattern pattern = Pattern.compile("\\G\\w");
1405 Matcher matcher = pattern.matcher("abc#x#x");
1406 matcher.find();
1407 matcher.find();
1408 matcher.find();
1409 if (matcher.find())
1410 failCount++;
1411
1412 pattern = Pattern.compile("\\GA*");
1413 matcher = pattern.matcher("1A2AA3");
1414 matcher.find();
1415 if (matcher.find())
1416 failCount++;
1417
1418 pattern = Pattern.compile("\\GA*");
1419 matcher = pattern.matcher("1A2AA3");
|