OSDN Git Service

original
[gb-231r1-is01/Gingerbread_2.3.3_r1_IS01.git] / libcore / luni / src / test / java / org / apache / harmony / regex / tests / java / util / regex / PatternTest.java
1 /*
2  *  Licensed to the Apache Software Foundation (ASF) under one or more
3  *  contributor license agreements.  See the NOTICE file distributed with
4  *  this work for additional information regarding copyright ownership.
5  *  The ASF licenses this file to You under the Apache License, Version 2.0
6  *  (the "License"); you may not use this file except in compliance with
7  *  the License.  You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  */
17
18 package org.apache.harmony.regex.tests.java.util.regex;
19
20 import java.io.Serializable;
21 import java.util.regex.Matcher;
22 import java.util.regex.Pattern;
23 import java.util.regex.PatternSyntaxException;
24
25 import junit.framework.TestCase;
26
27 import org.apache.harmony.testframework.serialization.SerializationTest;
28 import org.apache.harmony.testframework.serialization.SerializationTest.SerializableAssert;
29
30 import dalvik.annotation.TestLevel;
31 import dalvik.annotation.TestTargetClass;
32 import dalvik.annotation.TestTargetNew;
33 import dalvik.annotation.TestTargets;
34
35 @TestTargetClass(
36         value = Pattern.class,
37         untestedMethods= {
38             @TestTargetNew(
39                 level = TestLevel.NOT_FEASIBLE,
40                 notes = "finalize is hard to test since the implementation only calls a native function",
41                 method = "finalize",
42                 args = {}
43             )
44         }
45 )
46 public class PatternTest extends TestCase {
47     String[] testPatterns = {
48             "(a|b)*abb",
49             "(1*2*3*4*)*567",
50             "(a|b|c|d)*aab",
51             "(1|2|3|4|5|6|7|8|9|0)(1|2|3|4|5|6|7|8|9|0)*",
52             "(abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ)*",
53             "(a|b)*(a|b)*A(a|b)*lice.*",
54             "(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z)(a|b|c|d|e|f|g|h|"
55                     + "i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z)*(1|2|3|4|5|6|7|8|9|0)*|while|for|struct|if|do",
56 // BEGIN android-changed
57 // We don't have canonical equivalence.
58 //            "x(?c)y", "x(?cc)y"
59 //            "x(?:c)y"
60 // END android-changed
61
62     };
63
64     String[] testPatternsAlt = {
65             /*
66              * According to JavaDoc 2 and 3 oct digit sequences like \\o70\\o347
67              * should be OK, but test is failed for them
68              */
69             "[ab]\\b\\\\o5\\xF9\\u1E7B\\t\\n\\f\\r\\a\\e[yz]",
70             "^\\p{Lower}*\\p{Upper}*\\p{ASCII}?\\p{Alpha}?\\p{Digit}*\\p{Alnum}\\p{Punct}\\p{Graph}\\p{Print}\\p{Blank}\\p{Cntrl}\\p{XDigit}\\p{Space}",
71             "$\\p{javaLowerCase}\\p{javaUpperCase}\\p{javaWhitespace}\\p{javaMirrored}",
72             "\\p{InGreek}\\p{Lu}\\p{Sc}\\P{InGreek}[\\p{L}&&[^\\p{Lu}]]" };
73
74     String[] wrongTestPatterns = { "\\o9A", "\\p{Lawer}", "\\xG0" };
75
76     final static int[] flagsSet = { Pattern.CASE_INSENSITIVE,
77             Pattern.MULTILINE, Pattern.DOTALL, Pattern.UNICODE_CASE
78             /* , Pattern.CANON_EQ */ };
79
80     /*
81      * Based on RI implenetation documents. Need to check this set regarding
82      * actual implementation.
83      */
84     final static int[] wrongFlagsSet = { 256, 512, 1024 };
85
86     final static int DEFAULT_FLAGS = 0;
87
88     @TestTargetNew(
89         level = TestLevel.ADDITIONAL,
90         notes = "",
91         method = "!",
92         args = {}
93     )
94     public void testMatcher() {
95         // some very simple test
96         Pattern p = Pattern.compile("a");
97         assertNotNull(p.matcher("bcde"));
98         assertNotSame(p.matcher("a"), p.matcher("a"));
99     }
100
101     /*
102      * Class under test for String[] split(CharSequence, int)
103      */
104     @TestTargetNew(
105         level = TestLevel.PARTIAL_COMPLETE,
106         notes = "Verifies the functionality of splitsplit(java.lang.String, int) method.",
107         method = "split",
108         args = {CharSequence.class, int.class}
109     )
110     public void testSplitCharSequenceint() {
111         // splitting CharSequence which ends with pattern
112         // bug6193
113         assertEquals(",,".split(",", 3).length, 3);
114         assertEquals(",,".split(",", 4).length, 3);
115         // bug6193
116         // bug5391
117         assertEquals(Pattern.compile("o").split("boo:and:foo", 5).length, 5);
118         assertEquals(Pattern.compile("b").split("ab", -1).length, 2);
119         // bug5391
120         String s[];
121         Pattern pat = Pattern.compile("x");
122         s = pat.split("zxx:zzz:zxx", 10);
123         assertEquals(s.length, 5);
124         s = pat.split("zxx:zzz:zxx", 3);
125         assertEquals(s.length, 3);
126         s = pat.split("zxx:zzz:zxx", -1);
127         assertEquals(s.length, 5);
128         s = pat.split("zxx:zzz:zxx", 0);
129         assertEquals(s.length, 3);
130         // other splitting
131         // negative limit
132         pat = Pattern.compile("b");
133         s = pat.split("abccbadfebb", -1);
134         assertEquals(s.length, 5);
135         s = pat.split("", -1);
136         assertEquals(s.length, 1);
137         pat = Pattern.compile("");
138         s = pat.split("", -1);
139         assertEquals(s.length, 1);
140         s = pat.split("abccbadfe", -1);
141         assertEquals(s.length, 11);
142         // zero limit
143         pat = Pattern.compile("b");
144         s = pat.split("abccbadfebb", 0);
145         assertEquals(s.length, 3);
146         s = pat.split("", 0);
147         assertEquals(s.length, 1);
148         pat = Pattern.compile("");
149         s = pat.split("", 0);
150         assertEquals(s.length, 1);
151         s = pat.split("abccbadfe", 0);
152         assertEquals(s.length, 10);
153         // positive limit
154         pat = Pattern.compile("b");
155         s = pat.split("abccbadfebb", 12);
156         assertEquals(s.length, 5);
157         s = pat.split("", 6);
158         assertEquals(s.length, 1);
159         pat = Pattern.compile("");
160         s = pat.split("", 11);
161         assertEquals(s.length, 1);
162         s = pat.split("abccbadfe", 15);
163         assertEquals(s.length, 11);
164
165         pat = Pattern.compile("b");
166         s = pat.split("abccbadfebb", 5);
167         assertEquals(s.length, 5);
168         s = pat.split("", 1);
169         assertEquals(s.length, 1);
170         pat = Pattern.compile("");
171         s = pat.split("", 1);
172         assertEquals(s.length, 1);
173         s = pat.split("abccbadfe", 11);
174         assertEquals(s.length, 11);
175
176         pat = Pattern.compile("b");
177         s = pat.split("abccbadfebb", 3);
178         assertEquals(s.length, 3);
179         pat = Pattern.compile("");
180         s = pat.split("abccbadfe", 5);
181         assertEquals(s.length, 5);
182     }
183
184     /*
185      * Class under test for String[] split(CharSequence)
186      */
187     @TestTargetNew(
188         level = TestLevel.PARTIAL_COMPLETE,
189         notes = "Verifies the functionality of splitsplit(java.lang.String) method.",
190         method = "split",
191         args = {CharSequence.class}
192     )
193     public void testSplitCharSequence() {
194         String s[];
195         Pattern pat = Pattern.compile("b");
196         s = pat.split("abccbadfebb");
197         assertEquals(s.length, 3);
198         s = pat.split("");
199         assertEquals(s.length, 1);
200         pat = Pattern.compile("");
201         s = pat.split("");
202         assertEquals(s.length, 1);
203         s = pat.split("abccbadfe");
204         assertEquals(s.length, 10);
205         // bug6544
206         String s1 = "";
207         String[] arr = s1.split(":");
208         assertEquals(arr.length, 1);
209         // bug6544
210     }
211
212     @TestTargetNew(
213         level = TestLevel.COMPLETE,
214         notes = "Verifies the functionality of pattern() method.",
215         method = "pattern",
216         args = {}
217     )
218     public void testPattern() {
219         /* Positive assertion test. */
220         for (String aPattern : testPatterns) {
221             Pattern p = Pattern.compile(aPattern);
222             try {
223                 assertTrue(p.pattern().equals(aPattern));
224             } catch (Exception e) {
225                 fail("Unexpected exception: " + e);
226             }
227         }
228     }
229
230     @TestTargetNew(
231         level = TestLevel.PARTIAL_COMPLETE,
232         notes = "Verifies the functionality of compile(java.lang.String) method.",
233         method = "compile",
234         args = {java.lang.String.class}
235     )
236     public void testCompile() {
237         /* Positive assertion test. */
238         for (String aPattern : testPatterns) {
239             try {
240                 Pattern p = Pattern.compile(aPattern);
241             } catch (Exception e) {
242                 fail("Unexpected exception: " + e);
243             }
244         }
245
246         /* Positive assertion test with alternative templates. */
247         for (String aPattern : testPatternsAlt) {
248             try {
249                 Pattern p = Pattern.compile(aPattern);
250             } catch (Exception e) {
251                 fail("Unexpected exception: " + e);
252             }
253         }
254
255         /* Negative assertion test. */
256         for (String aPattern : wrongTestPatterns) {
257             try {
258                 Pattern p = Pattern.compile(aPattern);
259                 fail("PatternSyntaxException is expected");
260             } catch (PatternSyntaxException pse) {
261                 /* OKAY */
262             } catch (Exception e) {
263                 fail("Unexpected exception: " + e);
264             }
265         }
266     }
267
268     @TestTargetNew(
269         level = TestLevel.PARTIAL_COMPLETE,
270         notes = "Verifies the functionality of compile(java.lang.String) method for different flags.",
271         method = "compile",
272         args = {java.lang.String.class}
273     )
274     public void testFlags() {
275         String baseString;
276         String testString;
277         Pattern pat;
278         Matcher mat;
279
280         baseString = "((?i)|b)a";
281         testString = "A";
282         pat = Pattern.compile(baseString);
283         mat = pat.matcher(testString);
284         assertFalse(mat.matches());
285
286         baseString = "(?i)a|b";
287         testString = "A";
288         pat = Pattern.compile(baseString);
289         mat = pat.matcher(testString);
290         assertTrue(mat.matches());
291
292         baseString = "(?i)a|b";
293         testString = "B";
294         pat = Pattern.compile(baseString);
295         mat = pat.matcher(testString);
296         assertTrue(mat.matches());
297
298         baseString = "c|(?i)a|b";
299         testString = "B";
300         pat = Pattern.compile(baseString);
301         mat = pat.matcher(testString);
302         assertTrue(mat.matches());
303
304         baseString = "(?i)a|(?s)b";
305         testString = "B";
306         pat = Pattern.compile(baseString);
307         mat = pat.matcher(testString);
308         assertTrue(mat.matches());
309
310         baseString = "(?i)a|(?-i)b";
311         testString = "B";
312         pat = Pattern.compile(baseString);
313         mat = pat.matcher(testString);
314         assertFalse(mat.matches());
315
316         baseString = "(?i)a|(?-i)c|b";
317         testString = "B";
318         pat = Pattern.compile(baseString);
319         mat = pat.matcher(testString);
320         assertFalse(mat.matches());
321
322         baseString = "(?i)a|(?-i)c|(?i)b";
323         testString = "B";
324         pat = Pattern.compile(baseString);
325         mat = pat.matcher(testString);
326         assertTrue(mat.matches());
327
328         baseString = "(?i)a|(?-i)b";
329         testString = "A";
330         pat = Pattern.compile(baseString);
331         mat = pat.matcher(testString);
332         assertTrue(mat.matches());
333
334         baseString = "((?i))a";
335         testString = "A";
336         pat = Pattern.compile(baseString);
337         mat = pat.matcher(testString);
338         assertFalse(mat.matches());
339
340         baseString = "|(?i)|a";
341         testString = "A";
342         pat = Pattern.compile(baseString);
343         mat = pat.matcher(testString);
344         assertTrue(mat.matches());
345
346         baseString = "(?i)((?s)a.)";
347         testString = "A\n";
348         pat = Pattern.compile(baseString);
349         mat = pat.matcher(testString);
350         assertTrue(mat.matches());
351
352         baseString = "(?i)((?-i)a)";
353         testString = "A";
354         pat = Pattern.compile(baseString);
355         mat = pat.matcher(testString);
356         assertFalse(mat.matches());
357
358         baseString = "(?i)(?s:a.)";
359         testString = "A\n";
360         pat = Pattern.compile(baseString);
361         mat = pat.matcher(testString);
362         assertTrue(mat.matches());
363
364         baseString = "(?i)fgh(?s:aa)";
365         testString = "fghAA";
366         pat = Pattern.compile(baseString);
367         mat = pat.matcher(testString);
368         assertTrue(mat.matches());
369
370         baseString = "(?i)((?-i))a";
371         testString = "A";
372         pat = Pattern.compile(baseString);
373         mat = pat.matcher(testString);
374         assertTrue(mat.matches());
375
376         baseString = "abc(?i)d";
377         testString = "ABCD";
378         pat = Pattern.compile(baseString);
379         mat = pat.matcher(testString);
380         assertFalse(mat.matches());
381
382         testString = "abcD";
383         mat = pat.matcher(testString);
384         assertTrue(mat.matches());
385
386         baseString = "a(?i)a(?-i)a(?i)a(?-i)a";
387         testString = "aAaAa";
388         pat = Pattern.compile(baseString);
389         mat = pat.matcher(testString);
390         assertTrue(mat.matches());
391
392         testString = "aAAAa";
393         mat = pat.matcher(testString);
394         assertFalse(mat.matches());
395     }
396
397 // BEGIN android-removed
398 // The flags() method should only return those flags that were explicitly
399 // passed during the compilation. The JDK also accepts the ones implicitly
400 // contained in the pattern, but ICU doesn't do this.
401 //
402 //    public void testFlagsMethod() {
403 //        String baseString;
404 //        Pattern pat;
405 //
406 //        /*
407 //         * These tests are for compatibility with RI only. Logically we have to
408 //         * return only flags specified during the compilation. For example
409 //         * pat.flags() == 0 when we compile Pattern pat =
410 //         * Pattern.compile("(?i)abc(?-i)"); but the whole expression is compiled
411 //         * in a case insensitive manner. So there is little sense to do calls to
412 //         * flags() now.
413 //         */
414 //        baseString = "(?-i)";
415 //        pat = Pattern.compile(baseString);
416 //
417 //        baseString = "(?idmsux)abc(?-i)vg(?-dmu)";
418 //        pat = Pattern.compile(baseString);
419 //        assertEquals(pat.flags(), Pattern.DOTALL | Pattern.COMMENTS);
420 //
421 //        baseString = "(?idmsux)abc|(?-i)vg|(?-dmu)";
422 //        pat = Pattern.compile(baseString);
423 //        assertEquals(pat.flags(), Pattern.DOTALL | Pattern.COMMENTS);
424 //
425 //        baseString = "(?is)a((?x)b.)";
426 //        pat = Pattern.compile(baseString);
427 //        assertEquals(pat.flags(), Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
428 //
429 //        baseString = "(?i)a((?-i))";
430 //        pat = Pattern.compile(baseString);
431 //        assertEquals(pat.flags(), Pattern.CASE_INSENSITIVE);
432 //
433 //        baseString = "((?i)a)";
434 //        pat = Pattern.compile(baseString);
435 //        assertEquals(pat.flags(), 0);
436 //
437 //        pat = Pattern.compile("(?is)abc");
438 //        assertEquals(pat.flags(), Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
439 //    }
440 //END android-removed
441
442     /*
443      * Check default flags when they are not specified in pattern. Based on RI
444      * since could not find that info
445      */
446
447     @TestTargetNew(
448         level = TestLevel.PARTIAL_COMPLETE,
449         notes = "Verifies the functionality of flags() method for default flags.",
450         method = "flags",
451         args = {}
452     )
453     public void testFlagsCompileDefault() {
454         for (String pat : testPatternsAlt) {
455             try {
456                 Pattern p = Pattern.compile(pat);
457                 assertEquals(p.flags(), DEFAULT_FLAGS);
458             } catch (Exception e) {
459                 fail("Unexpected exception: " + e);
460             }
461         }
462     }
463
464     /*
465      * Check that flags specified during compile are set properly This is a
466      * simple implementation that does not use flags combinations. Need to
467      * improve.
468      */
469
470     @TestTargets({
471         @TestTargetNew(
472             level = TestLevel.PARTIAL_COMPLETE,
473             notes = "Verifies the functionality of compile(java.lang.String, int) & flags() methods. Checks that compilation was corect.",
474             method = "flags",
475             args = {}
476         ),
477         @TestTargetNew(
478             level = TestLevel.PARTIAL_COMPLETE,
479             notes = "Verifies the functionality of compile(java.lang.String, int) & flags() methods. Checks that compilation was corect.",
480             method = "compile",
481             args = {java.lang.String.class, int.class}
482         )
483     })
484     public void testFlagsCompileValid() {
485         for (String pat : testPatternsAlt) {
486             for (int flags : flagsSet) {
487                 try {
488                     Pattern p = Pattern.compile(pat, flags);
489                     assertEquals(p.flags(), flags);
490                 } catch (Exception e) {
491                     fail("Unexpected exception: " + e);
492                 }
493             }
494         }
495     }
496
497     /*
498      * Class under test for Pattern compile(String, int)
499      */
500
501     @TestTargetNew(
502         level = TestLevel.PARTIAL_COMPLETE,
503         notes = "Verifies the functionality of compile(java.lang.String) method.Checks that correct exceptions were thrown.",
504         method = "compile",
505         args = {java.lang.String.class}
506     )
507     public void testCompileStringint() {
508         /*
509          * these tests are needed to verify that appropriate exceptions are
510          * thrown
511          */
512         String pattern = "b)a";
513         try {
514             Pattern.compile(pattern);
515             fail("Expected a PatternSyntaxException when compiling pattern: "
516                     + pattern);
517         } catch (PatternSyntaxException e) {
518             // pass
519         }
520         pattern = "bcde)a";
521         try {
522             Pattern.compile(pattern);
523             fail("Expected a PatternSyntaxException when compiling pattern: "
524                     + pattern);
525         } catch (PatternSyntaxException e) {
526             // pass
527         }
528         pattern = "bbg())a";
529         try {
530             Pattern pat = Pattern.compile(pattern);
531             fail("Expected a PatternSyntaxException when compiling pattern: "
532                     + pattern);
533         } catch (PatternSyntaxException e) {
534             // pass
535         }
536
537         pattern = "cdb(?i))a";
538         try {
539             Pattern pat = Pattern.compile(pattern);
540             fail("Expected a PatternSyntaxException when compiling pattern: "
541                     + pattern);
542         } catch (PatternSyntaxException e) {
543             // pass
544         }
545
546         /*
547          * This pattern should compile - HARMONY-2127
548          */
549 //        pattern = "x(?c)y";
550 //        Pattern.compile(pattern);
551
552         /*
553          * this pattern doesn't match any string, but should be compiled anyway
554          */
555         pattern = "(b\\1)a";
556         Pattern.compile(pattern);
557     }
558
559     /*
560      * Class under test for Pattern compile(String)
561      */
562     @TestTargetNew(
563         level = TestLevel.PARTIAL_COMPLETE,
564         notes = "Verifies the functionality of compile(java.lang.String) method.Checks that correct exceptions were thrown.",
565         method = "compile",
566         args = {java.lang.String.class}
567     )
568     public void testQuantCompileNeg() {
569         String[] patterns = { "5{,2}", "{5asd", "{hgdhg", "{5,hjkh", "{,5hdsh",
570                 "{5,3shdfkjh}" };
571         for (String element : patterns) {
572             try {
573                 Pattern.compile(element);
574                 fail("PatternSyntaxException was expected, but compilation succeeds");
575             } catch (PatternSyntaxException pse) {
576                 continue;
577             }
578         }
579         // Regression for HARMONY-1365
580 // BEGIN android-changed
581 // Original regex contained some illegal stuff. Changed it slightly,
582 // while maintaining the wicked character of this "mother of all
583 // regexes".
584 //        String pattern = "(?![^\\<C\\f\\0146\\0270\\}&&[|\\02-\\x3E\\}|X-\\|]]{7,}+)[|\\\\\\x98\\<\\?\\u4FCFr\\,\\0025\\}\\004|\\0025-\\052\061]|(?<![|\\01-\\u829E])|(?<!\\p{Alpha})|^|(?-s:[^\\x15\\\\\\x24F\\a\\,\\a\\u97D8[\\x38\\a[\\0224-\\0306[^\\0020-\\u6A57]]]]??)(?uxix:[^|\\{\\[\\0367\\t\\e\\x8C\\{\\[\\074c\\]V[|b\\fu\\r\\0175\\<\\07f\\066s[^D-\\x5D]]])(?xx:^{5,}+)(?uuu)(?=^\\D)|(?!\\G)(?>\\G*?)(?![^|\\]\\070\\ne\\{\\t\\[\\053\\?\\\\\\x51\\a\\075\\0023-\\[&&[|\\022-\\xEA\\00-\\u41C2&&[^|a-\\xCC&&[^\\037\\uECB3\\u3D9A\\x31\\|\\<b\\0206\\uF2EC\\01m\\,\\ak\\a\\03&&\\p{Punct}]]]])(?-dxs:[|\\06-\\07|\\e-\\x63&&[|Tp\\u18A3\\00\\|\\xE4\\05\\061\\015\\0116C|\\r\\{\\}\\006\\xEA\\0367\\xC4\\01\\0042\\0267\\xBB\\01T\\}\\0100\\?[|\\[-\\u459B|\\x23\\x91\\rF\\0376[|\\?-\\x94\\0113-\\\\\\s]]]]{6}?)(?<=[^\\t-\\x42H\\04\\f\\03\\0172\\?i\\u97B6\\e\\f\\uDAC2])(?=\\B*+)(?>[^\\016\\r\\{\\,\\uA29D\\034\\02[\\02-\\[|\\t\\056\\uF599\\x62\\e\\<\\032\\uF0AC\\0026\\0205Q\\|\\\\\\06\\0164[|\\057-\\u7A98&&[\\061-g|\\|\\0276\\n\\042\\011\\e\\xE8\\x64B\\04\\u6D0EDW^\\p{Lower}]]]]?)(?<=[^\\n\\\\\\t\\u8E13\\,\\0114\\u656E\\xA5\\]&&[\\03-\\026|\\uF39D\\01\\{i\\u3BC2\\u14FE]])(?<=[^|\\uAE62\\054H\\|\\}&&^\\p{Space}])(?sxx)(?<=[\\f\\006\\a\\r\\xB4]*+)|(?x-xd:^{5}+)()";
585         String pattern = "(?![^\\<C\\f\\0146\\0270\\}&&[|\\02-\\x3E\\}|X-\\|]]{7,}+)[|\\\\\\x98\\<\\?\\u4FCFr\\,\\0025\\}\\004|\\0025-\\052\061]|(?<![|\\01-\\u829E])|(?<!\\p{Alpha})|^|(?-s:[^\\x15\\\\\\x24F\\a\\,\\a\\u97D8[\\x38\\a[\\0224-\\0306[^\\0020-\\u6A57]]]]??)(?uxix:[^|\\{\\[\\0367\\t\\e\\x8C\\{\\[\\074c\\]V[|b\\fu\\r\\0175\\<\\07f\\066s[^D-\\x5D]]])(?xx:^{5,}+)(?uuu)(?=^\\D)|(?!\\G)(?>\\.*?)(?![^|\\]\\070\\ne\\{\\t\\[\\053\\?\\\\\\x51\\a\\075\\0023-\\[&&[|\\022-\\xEA\\00-\\u41C2&&[^|a-\\xCC&&[^\\037\\uECB3\\u3D9A\\x31\\|\\<b\\0206\\uF2EC\\01m\\,\\ak\\a\\03&&\\p{Punct}]]]])(?-dxs:[|\\06-\\07|\\e-\\x63&&[|Tp\\u18A3\\00\\|\\xE4\\05\\061\\015\\0116C|\\r\\{\\}\\006\\xEA\\0367\\xC4\\01\\0042\\0267\\xBB\\01T\\}\\0100\\?[|\\[-\\u459B|\\x23\\x91\\rF\\0376[|\\?-\\x94\\0113-\\\\\\s]]]]{6}?)(?<=[^\\t-\\x42H\\04\\f\\03\\0172\\?i\\u97B6\\e\\f\\uDAC2])(?=\\.*+)(?>[^\\016\\r\\{\\,\\uA29D\\034\\02[\\02-\\[|\\t\\056\\uF599\\x62\\e\\<\\032\\uF0AC\\0026\\0205Q\\|\\\\\\06\\0164[|\\057-\\u7A98&&[\\061-g|\\|\\0276\\n\\042\\011\\e\\xE8\\x64B\\04\\u6D0EDW^\\p{Lower}]]]]?)(?<=[^\\n\\\\\\t\\u8E13\\,\\0114\\u656E\\xA5\\]&&[\\03-\\026|\\uF39D\\01\\{i\\u3BC2\\u14FE]])(?<=[^|\\uAE62\\054H\\|\\}&&^\\p{Space}])(?sxx)(?<=[\\f\\006\\a\\r\\xB4]{1,5})|(?x-xd:^{5}+)()";
586 // END android-changed
587         assertNotNull(Pattern.compile(pattern));
588     }
589
590     @TestTargetNew(
591         level = TestLevel.PARTIAL_COMPLETE,
592         notes = "Verifies the functionality of compile(java.lang.String) method.",
593         method = "compile",
594         args = {java.lang.String.class}
595     )
596     public void testQuantCompilePos() {
597         String[] patterns = {/* "(abc){1,3}", */"abc{2,}", "abc{5}" };
598         for (String element : patterns) {
599             Pattern.compile(element);
600         }
601     }
602
603     @TestTargetNew(
604         level = TestLevel.PARTIAL_COMPLETE,
605         notes = "Verifies the functionality of compile() method. Also tested methods from matcher: matches(), start(int), group(int)",
606         method = "compile",
607         args = {java.lang.String.class}
608     )
609     public void testQuantComposition() {
610         String pattern = "(a{1,3})aab";
611         java.util.regex.Pattern pat = java.util.regex.Pattern.compile(pattern);
612         java.util.regex.Matcher mat = pat.matcher("aaab");
613         mat.matches();
614         mat.start(1);
615         mat.group(1);
616     }
617
618     @TestTargetNew(
619         level = TestLevel.PARTIAL_COMPLETE,
620         notes = "",
621         method = "matches",
622         args = {java.lang.String.class, java.lang.CharSequence.class}
623     )
624     public void testMatches() {
625         String[][] posSeq = {
626                 { "abb", "ababb", "abababbababb", "abababbababbabababbbbbabb" },
627                 { "213567", "12324567", "1234567", "213213567",
628                         "21312312312567", "444444567" },
629                 { "abcdaab", "aab", "abaab", "cdaab", "acbdadcbaab" },
630                 { "213234567", "3458", "0987654", "7689546432", "0398576",
631                         "98432", "5" },
632                 {
633                         "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
634                         "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
635                                 + "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" },
636                 { "ababbaAabababblice", "ababbaAliceababab", "ababbAabliceaaa",
637                         "abbbAbbbliceaaa", "Alice" },
638                 { "a123", "bnxnvgds156", "for", "while", "if", "struct" },
639                 { "xy" }, { "xy" }, { "xcy" }
640
641         };
642
643         for (int i = 0; i < testPatterns.length; i++) {
644             for (int j = 0; j < posSeq[i].length; j++) {
645                 assertTrue("Incorrect match: " + testPatterns[i] + " vs "
646                         + posSeq[i][j], Pattern.matches(testPatterns[i],
647                         posSeq[i][j]));
648             }
649         }
650     }
651
652     @TestTargetNew(
653         level = TestLevel.PARTIAL_COMPLETE,
654         notes = "Verifies exception",
655         method = "matches",
656         args = {java.lang.String.class, java.lang.CharSequence.class}
657     )
658     public void testMatchesException() {
659         /* Negative assertion test. */
660         for (String aPattern : wrongTestPatterns) {
661             try {
662                 Pattern.matches(aPattern, "Foo");
663                 fail("PatternSyntaxException is expected");
664             } catch (PatternSyntaxException pse) {
665                 /* OKAY */
666             } catch (Exception e) {
667                 fail("Unexpected exception: " + e);
668             }
669         }
670     }
671
672     @TestTargetNew(
673         level = TestLevel.PARTIAL_COMPLETE,
674         notes = "The test verifies the functionality of matches(java.lang.String,java.lang.CharSequence) method.",
675         method = "matches",
676         args = {java.lang.String.class, java.lang.CharSequence.class}
677     )
678     public void testTimeZoneIssue() {
679         Pattern p = Pattern.compile("GMT(\\+|\\-)(\\d+)(:(\\d+))?");
680         Matcher m = p.matcher("GMT-9:45");
681         assertTrue(m.matches());
682         assertEquals("-", m.group(1));
683         assertEquals("9", m.group(2));
684         assertEquals(":45", m.group(3));
685         assertEquals("45", m.group(4));
686     }
687
688 // BEGIN android-changed
689 // Removed one pattern that is buggy on the JDK. We don't want to duplicate that.
690     @TestTargetNew(
691         level = TestLevel.PARTIAL_COMPLETE,
692         notes = "Verifies the functionality of matches(java.lang.String,java.lang.CharSequence) method.",
693         method = "matches",
694         args = {java.lang.String.class, java.lang.CharSequence.class}
695     )
696     public void testCompileRanges() {
697         String[] correctTestPatterns = { "[^]*abb]*", /* "[^a-d[^m-p]]*abb", */
698                 "[a-d\\d]*abb", "[abc]*abb", "[a-e&&[de]]*abb", "[^abc]*abb",
699                 "[a-e&&[^de]]*abb", "[a-z&&[^m-p]]*abb", "[a-d[m-p]]*abb",
700                 "[a-zA-Z]*abb", "[+*?]*abb", "[^+*?]*abb" };
701
702         String[] inputSecuence = { "kkkk", /* "admpabb", */ "abcabcd124654abb",
703                 "abcabccbacababb", "dededededededeedabb", "gfdhfghgdfghabb",
704                 "accabacbcbaabb", "acbvfgtyabb", "adbcacdbmopabcoabb",
705                 "jhfkjhaSDFGHJkdfhHNJMjkhfabb", "+*??+*abb", "sdfghjkabb" };
706
707         Pattern pat;
708
709         for (int i = 0; i < correctTestPatterns.length; i++) {
710             assertTrue("pattern: " + correctTestPatterns[i] + " input: "
711                     + inputSecuence[i], Pattern.matches(correctTestPatterns[i],
712                     inputSecuence[i]));
713
714         }
715
716         String[] wrongInputSecuence = { "]", /* "admpkk", */  "abcabcd124k654abb",
717                 "abwcabccbacababb", "abababdeababdeabb", "abcabcacbacbabb",
718                 "acdcbecbaabb", "acbotyabb", "adbcaecdbmopabcoabb",
719                 "jhfkjhaSDFGHJk;dfhHNJMjkhfabb", "+*?a?+*abb", "sdf+ghjkabb" };
720
721         for (int i = 0; i < correctTestPatterns.length; i++) {
722             assertFalse("pattern: " + correctTestPatterns[i] + " input: "
723                     + wrongInputSecuence[i], Pattern.matches(
724                     correctTestPatterns[i], wrongInputSecuence[i]));
725
726         }
727     }
728
729     @TestTargetNew(
730         level = TestLevel.PARTIAL_COMPLETE,
731         notes = "Verifies the functionality of matches(java.lang.String,java.lang.CharSequence) method for ranged patterns.",
732         method = "matches",
733         args = {java.lang.String.class, java.lang.CharSequence.class}
734     )
735     public void testRangesSpecialCases() {
736         String neg_patterns[] = { "[a-&&[b-c]]", "[a-\\w]", "[b-a]", "[]" };
737
738         for (String element : neg_patterns) {
739             try {
740                 Pattern.compile(element);
741                 fail("PatternSyntaxException was expected: " + element);
742             } catch (PatternSyntaxException pse) {
743             }
744         }
745
746         String pos_patterns[] = { "[-]+", "----", "[a-]+", "a-a-a-a-aa--",
747                 "[\\w-a]+", "123-2312--aaa-213", "[a-]]+", "-]]]]]]]]]]]]]]]" };
748
749         for (int i = 0; i < pos_patterns.length; i++) {
750             String pat = pos_patterns[i++];
751             String inp = pos_patterns[i];
752             assertTrue("pattern: " + pat + " input: " + inp, Pattern.matches(
753                     pat, inp));
754         }
755     }
756  // END android-changed
757
758     @TestTargetNew(
759         level = TestLevel.PARTIAL_COMPLETE,
760         notes = "The test verifies the functionality of matches(java.lang.String,java.lang.CharSequence) method.",
761         method = "matches",
762         args = {java.lang.String.class, java.lang.CharSequence.class}
763     )
764 public void testZeroSymbols() {
765         assertTrue(Pattern.matches("[\0]*abb", "\0\0\0\0\0\0abb"));
766     }
767
768     @TestTargetNew(
769         level = TestLevel.PARTIAL_COMPLETE,
770         notes = "Verifies the functionality of matcher(java.lang.String) method.",
771         method = "matcher",
772         args = {CharSequence.class}
773     )
774     public void testEscapes() {
775         Pattern pat = Pattern.compile("\\Q{]()*?");
776         Matcher mat = pat.matcher("{]()*?");
777
778         assertTrue(mat.matches());
779     }
780
781     @TestTargetNew(
782         level = TestLevel.PARTIAL_COMPLETE,
783         notes = "Verifies the functionality of compile(java.lang.String) method.",
784         method = "compile",
785         args = {java.lang.String.class}
786     )
787     public void testBug181() {
788         Pattern.compile("[\\t-\\r]");
789     }
790
791     @TestTargetNew(
792         level = TestLevel.PARTIAL_COMPLETE,
793         notes = "Verifies the functionality of compile(java.lang.String) method.",
794         method = "compile",
795         args = {java.lang.String.class}
796     )
797     public void testOrphanQuantifiers() {
798         try {
799             Pattern.compile("+++++");
800             fail("PatternSyntaxException expected");
801         } catch (PatternSyntaxException pse) {
802         }
803     }
804
805     @TestTargetNew(
806         level = TestLevel.PARTIAL_COMPLETE,
807         notes = "Verifies the functionality of compile(java.lang.String) method.",
808         method = "compile",
809         args = {java.lang.String.class}
810     )
811     public void testOrphanQuantifiers2() {
812         try {
813             Pattern pat = Pattern.compile("\\d+*");
814             fail("PatternSyntaxException expected");
815         } catch (PatternSyntaxException pse) {
816         }
817     }
818
819
820     @TestTargets({
821         @TestTargetNew(
822             level = TestLevel.PARTIAL_COMPLETE,
823             notes = "Verifies the functionality of compile(java.lang.String) method.",
824             method = "compile",
825             args = {java.lang.String.class}
826         ),
827         @TestTargetNew(
828             level = TestLevel.PARTIAL_COMPLETE,
829             notes = "Verifies the functionality of compile(java.lang.String) method.",
830             method = "compile",
831             args = {java.lang.String.class}
832         )
833     })
834     public void testBug197() {
835         Object[] vals = { ":", new Integer(2),
836                 new String[] { "boo", "and:foo" }, ":", new Integer(5),
837                 new String[] { "boo", "and", "foo" }, ":", new Integer(-2),
838                 new String[] { "boo", "and", "foo" }, ":", new Integer(3),
839                 new String[] { "boo", "and", "foo" }, ":", new Integer(1),
840                 new String[] { "boo:and:foo" }, "o", new Integer(5),
841                 new String[] { "b", "", ":and:f", "", "" }, "o",
842                 new Integer(4), new String[] { "b", "", ":and:f", "o" }, "o",
843                 new Integer(-2), new String[] { "b", "", ":and:f", "", "" },
844                 "o", new Integer(0), new String[] { "b", "", ":and:f" } };
845
846         for (int i = 0; i < vals.length / 3;) {
847             String[] res = Pattern.compile(vals[i++].toString()).split(
848                     "boo:and:foo", ((Integer) vals[i++]).intValue());
849             String[] expectedRes = (String[]) vals[i++];
850
851             assertEquals(expectedRes.length, res.length);
852
853             for (int j = 0; j < expectedRes.length; j++) {
854                 assertEquals(expectedRes[j], res[j]);
855             }
856         }
857     }
858
859
860     @TestTargetNew(
861         level = TestLevel.PARTIAL_COMPLETE,
862         notes = "The test verifies the functionality of compile(java.lang.String) method.",
863         method = "compile",
864         args = {java.lang.String.class}
865     )
866     public void testURIPatterns() {
867         String URI_REGEXP_STR = "^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?";
868         String SCHEME_REGEXP_STR = "^[a-zA-Z]{1}[\\w+-.]+$";
869         String REL_URI_REGEXP_STR = "^(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?";
870         String IPV6_REGEXP_STR = "^[0-9a-fA-F\\:\\.]+(\\%\\w+)?$";
871         String IPV6_REGEXP_STR2 = "^\\[[0-9a-fA-F\\:\\.]+(\\%\\w+)?\\]$";
872         String IPV4_REGEXP_STR = "^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$";
873         String HOSTNAME_REGEXP_STR = "\\w+[\\w\\-\\.]*";
874
875         Pattern URI_REGEXP = Pattern.compile(URI_REGEXP_STR);
876         Pattern REL_URI_REGEXP = Pattern.compile(REL_URI_REGEXP_STR);
877         Pattern SCHEME_REGEXP = Pattern.compile(SCHEME_REGEXP_STR);
878         Pattern IPV4_REGEXP = Pattern.compile(IPV4_REGEXP_STR);
879         Pattern IPV6_REGEXP = Pattern.compile(IPV6_REGEXP_STR);
880         Pattern IPV6_REGEXP2 = Pattern.compile(IPV6_REGEXP_STR2);
881         Pattern HOSTNAME_REGEXP = Pattern.compile(HOSTNAME_REGEXP_STR);
882     }
883
884     @TestTargetNew(
885         level = TestLevel.PARTIAL_COMPLETE,
886         notes = "Verifies the functionality of compile(java.lang.String) method.",
887         method = "compile",
888         args = {java.lang.String.class}
889     )
890     public void testFindBoundaryCases1() {
891         Pattern pat = Pattern.compile(".*\n");
892         Matcher mat = pat.matcher("a\n");
893
894         mat.find();
895         assertEquals("a\n", mat.group());
896     }
897
898     @TestTargetNew(
899         level = TestLevel.PARTIAL_COMPLETE,
900         notes = "Verifies the functionality of compile(java.lang.String) method.",
901         method = "compile",
902         args = {java.lang.String.class}
903     )
904     public void testFindBoundaryCases2() {
905         Pattern pat = Pattern.compile(".*A");
906         Matcher mat = pat.matcher("aAa");
907
908         mat.find();
909         assertEquals("aA", mat.group());
910     }
911
912     @TestTargetNew(
913         level = TestLevel.PARTIAL_COMPLETE,
914         notes = "Verifies the functionality of compile(java.lang.String) method.",
915         method = "compile",
916         args = {java.lang.String.class}
917     )
918     public void testFindBoundaryCases3() {
919         Pattern pat = Pattern.compile(".*A");
920         Matcher mat = pat.matcher("a\naA\n");
921
922         mat.find();
923         assertEquals("aA", mat.group());
924     }
925
926     @TestTargetNew(
927         level = TestLevel.PARTIAL_COMPLETE,
928         notes = "Verifies the functionality of compile(java.lang.String) method.",
929         method = "compile",
930         args = {java.lang.String.class}
931     )
932     public void testFindBoundaryCases4() {
933         Pattern pat = Pattern.compile("A.*");
934         Matcher mat = pat.matcher("A\n");
935
936         mat.find();
937         assertEquals("A", mat.group());
938     }
939
940     @TestTargetNew(
941         level = TestLevel.PARTIAL_COMPLETE,
942         notes = "Verifies the functionality of compile(java.lang.String) method.",
943         method = "compile",
944         args = {java.lang.String.class}
945     )
946     public void testFindBoundaryCases5() {
947         Pattern pat = Pattern.compile(".*A.*");
948         Matcher mat = pat.matcher("\nA\naaa\nA\naaAaa\naaaA\n");
949         // Matcher mat = pat.matcher("\nA\n");
950         String[] res = { "A", "A", "aaAaa", "aaaA" };
951         int k = 0;
952         for (; mat.find(); k++) {
953             assertEquals(res[k], mat.group());
954         }
955     }
956
957     @TestTargetNew(
958         level = TestLevel.PARTIAL_COMPLETE,
959         notes = "Verifies the functionality of compile(java.lang.String) method.",
960         method = "compile",
961         args = {java.lang.String.class}
962     )
963     public void testFindBoundaryCases6() {
964         String[] res = { "", "a", "", "" };
965         Pattern pat = Pattern.compile(".*");
966         Matcher mat = pat.matcher("\na\n");
967         int k = 0;
968
969         for (; mat.find(); k++) {
970             assertEquals(res[k], mat.group());
971         }
972     }
973
974     @TestTargets({
975         @TestTargetNew(
976             level = TestLevel.PARTIAL_COMPLETE,
977             notes = "Verifies the functionality of compile(java.lang.String) & matcher(java.lang.CharSequence) methods.",
978             method = "compile",
979             args = {java.lang.String.class}
980         ),
981         @TestTargetNew(
982             level = TestLevel.PARTIAL_COMPLETE,
983             notes = "Verifies the functionality of compile(java.lang.String) & matcher(java.lang.CharSequence) methods.",
984             method = "matcher",
985             args = {java.lang.CharSequence.class}
986         )
987     })
988     public void testBackReferences() {
989         Pattern pat = Pattern.compile("(\\((\\w*):(.*):(\\2)\\))");
990         Matcher mat = pat
991                 .matcher("(start1: word :start1)(start2: word :start2)");
992         int k = 1;
993         for (; mat.find(); k++) {
994             assertEquals("start" + k, mat.group(2));
995             assertEquals(" word ", mat.group(3));
996             assertEquals("start" + k, mat.group(4));
997         }
998
999         assertEquals(3, k);
1000         pat = Pattern.compile(".*(.)\\1");
1001         mat = pat.matcher("saa");
1002         assertTrue(mat.matches());
1003     }
1004
1005     @TestTargets({
1006         @TestTargetNew(
1007             level = TestLevel.PARTIAL_COMPLETE,
1008             notes = "Verifies the functionality of compile(java.lang.String, int) & matcher(java.lang.CharSequence) methods.",
1009             method = "compile",
1010             args = {java.lang.String.class, int.class}
1011         ),
1012         @TestTargetNew(
1013             level = TestLevel.PARTIAL_COMPLETE,
1014             notes = "Verifies the functionality of compile(java.lang.String, int) & matcher(java.lang.CharSequence) methods.",
1015             method = "matcher",
1016             args = {java.lang.CharSequence.class}
1017         )
1018     })
1019     public void testNewLine() {
1020         Pattern pat = Pattern.compile("(^$)*\n", Pattern.MULTILINE);
1021         Matcher mat = pat.matcher("\r\n\n");
1022         int counter = 0;
1023         while (mat.find()) {
1024             counter++;
1025         }
1026         assertEquals(2, counter);
1027     }
1028
1029     @TestTargets({
1030         @TestTargetNew(
1031             level = TestLevel.PARTIAL_COMPLETE,
1032             notes = "Verifies the functionality of compile(java.lang.String, int) & matcher(java.lang.CharSequence) methods.",
1033             method = "compile",
1034             args = {java.lang.String.class, int.class}
1035         ),
1036         @TestTargetNew(
1037             level = TestLevel.PARTIAL_COMPLETE,
1038             notes = "Verifies the functionality of compile(java.lang.String, int) & matcher(java.lang.CharSequence) methods.",
1039             method = "matcher",
1040             args = {java.lang.CharSequence.class}
1041         )
1042     })
1043     public void testFindGreedy() {
1044         Pattern pat = Pattern.compile(".*aaa", Pattern.DOTALL);
1045         Matcher mat = pat.matcher("aaaa\naaa\naaaaaa");
1046         mat.matches();
1047         assertEquals(15, mat.end());
1048     }
1049     @TestTargets({
1050         @TestTargetNew(
1051             level = TestLevel.PARTIAL_COMPLETE,
1052             notes = "Verifies serialization/deserialization.",
1053             method = "!SerializationSelf",
1054             args = {}
1055         ),
1056         @TestTargetNew(
1057             level = TestLevel.PARTIAL_COMPLETE,
1058             notes = "Verifies serialization/deserialization.",
1059             method = "!SerializationGolden",
1060             args = {}
1061         )
1062     })
1063     public void testSerialization() throws Exception {
1064         Pattern pat = Pattern.compile("a*bc");
1065         SerializableAssert comparator = new SerializableAssert() {
1066             public void assertDeserialized(Serializable initial,
1067                     Serializable deserialized) {
1068                 assertEquals(((Pattern) initial).toString(),
1069                         ((Pattern) deserialized).toString());
1070             }
1071         };
1072         SerializationTest.verifyGolden(this, pat, comparator);
1073         SerializationTest.verifySelf(pat, comparator);
1074     }
1075
1076     @TestTargets({
1077         @TestTargetNew(
1078             level = TestLevel.PARTIAL_COMPLETE,
1079             notes = "Verifies the functionality of compile(java.lang.String, int) & matcher(java.lang.CharSequence) methods.",
1080             method = "compile",
1081             args = {java.lang.String.class, int.class}
1082         ),
1083         @TestTargetNew(
1084             level = TestLevel.PARTIAL_COMPLETE,
1085             notes = "Verifies the functionality of compile(java.lang.String, int) & matcher(java.lang.CharSequence) methods.",
1086             method = "matcher",
1087             args = {java.lang.CharSequence.class}
1088         )
1089     })
1090     public void testSOLQuant() {
1091         Pattern pat = Pattern.compile("$*", Pattern.MULTILINE);
1092         Matcher mat = pat.matcher("\n\n");
1093         int counter = 0;
1094         while (mat.find()) {
1095             counter++;
1096         }
1097
1098         assertEquals(3, counter);
1099     }
1100
1101     @TestTargetNew(
1102         level = TestLevel.PARTIAL_COMPLETE,
1103         notes = "Verifies the functionality of compile(java.lang.String) method.",
1104         method = "compile",
1105         args = {java.lang.String.class}
1106     )
1107     public void testIllegalEscape() {
1108         try {
1109             Pattern.compile("\\y");
1110             fail("PatternSyntaxException expected");
1111         } catch (PatternSyntaxException pse) {
1112         }
1113     }
1114
1115     @TestTargetNew(
1116         level = TestLevel.PARTIAL_COMPLETE,
1117         notes = "Verifies the functionality of compile(java.lang.String) method.",
1118         method = "compile",
1119         args = {java.lang.String.class}
1120     )
1121     public void testEmptyFamily() {
1122         Pattern.compile("\\p{Lower}");
1123         String a = "*";
1124     }
1125
1126     @TestTargets({
1127         @TestTargetNew(
1128             level = TestLevel.PARTIAL_COMPLETE,
1129             notes = "Verifies the functionality of compile(java.lang.String) & matcher(java.lang.CharSequence) methods.",
1130             method = "compile",
1131             args = {java.lang.String.class}
1132         ),
1133         @TestTargetNew(
1134             level = TestLevel.PARTIAL_COMPLETE,
1135             notes = "Verifies the functionality of compile(java.lang.String) & matcher(java.lang.CharSequence) methods.",
1136             method = "matcher",
1137             args = {java.lang.CharSequence.class}
1138         )
1139     })
1140     public void testNonCaptConstr() {
1141         // Flags
1142         Pattern pat = Pattern.compile("(?i)b*(?-i)a*");
1143         assertTrue(pat.matcher("bBbBaaaa").matches());
1144         assertFalse(pat.matcher("bBbBAaAa").matches());
1145
1146         // Non-capturing groups
1147         pat = Pattern.compile("(?i:b*)a*");
1148         assertTrue(pat.matcher("bBbBaaaa").matches());
1149         assertFalse(pat.matcher("bBbBAaAa").matches());
1150
1151         pat = Pattern
1152         // 1 2 3 4 5 6 7 8 9 10 11
1153                 .compile("(?:-|(-?\\d+\\d\\d\\d))?(?:-|-(\\d\\d))?(?:-|-(\\d\\d))?(T)?(?:(\\d\\d):(\\d\\d):(\\d\\d)(\\.\\d+)?)?(?:(?:((?:\\+|\\-)\\d\\d):(\\d\\d))|(Z))?");
1154         Matcher mat = pat.matcher("-1234-21-31T41:51:61.789+71:81");
1155         assertTrue(mat.matches());
1156         assertEquals("-1234", mat.group(1));
1157         assertEquals("21", mat.group(2));
1158         assertEquals("31", mat.group(3));
1159         assertEquals("T", mat.group(4));
1160         assertEquals("41", mat.group(5));
1161         assertEquals("51", mat.group(6));
1162         assertEquals("61", mat.group(7));
1163         assertEquals(".789", mat.group(8));
1164         assertEquals("+71", mat.group(9));
1165         assertEquals("81", mat.group(10));
1166
1167         // positive lookahead
1168         pat = Pattern.compile(".*\\.(?=log$).*$");
1169         assertTrue(pat.matcher("a.b.c.log").matches());
1170         assertFalse(pat.matcher("a.b.c.log.").matches());
1171
1172         // negative lookahead
1173         pat = Pattern.compile(".*\\.(?!log$).*$");
1174         assertFalse(pat.matcher("abc.log").matches());
1175         assertTrue(pat.matcher("abc.logg").matches());
1176
1177         // positive lookbehind
1178         pat = Pattern.compile(".*(?<=abc)\\.log$");
1179         assertFalse(pat.matcher("cde.log").matches());
1180         assertTrue(pat.matcher("abc.log").matches());
1181
1182         // negative lookbehind
1183         pat = Pattern.compile(".*(?<!abc)\\.log$");
1184         assertTrue(pat.matcher("cde.log").matches());
1185         assertFalse(pat.matcher("abc.log").matches());
1186
1187         // atomic group
1188         pat = Pattern.compile("(?>a*)abb");
1189         assertFalse(pat.matcher("aaabb").matches());
1190         pat = Pattern.compile("(?>a*)bb");
1191         assertTrue(pat.matcher("aaabb").matches());
1192
1193         pat = Pattern.compile("(?>a|aa)aabb");
1194         assertTrue(pat.matcher("aaabb").matches());
1195         pat = Pattern.compile("(?>aa|a)aabb");
1196         assertFalse(pat.matcher("aaabb").matches());
1197
1198 // BEGIN android-removed
1199 // Questionable constructs that ICU doesn't support.
1200 //        // quantifiers over look ahead
1201 //        pat = Pattern.compile(".*(?<=abc)*\\.log$");
1202 //        assertTrue(pat.matcher("cde.log").matches());
1203 //        pat = Pattern.compile(".*(?<=abc)+\\.log$");
1204 //        assertFalse(pat.matcher("cde.log").matches());
1205 // END android-removed
1206
1207     }
1208
1209     @TestTargetNew(
1210         level = TestLevel.PARTIAL_COMPLETE,
1211         notes = "Verifies the functionality of compile(java.lang.String) method.",
1212         method = "compile",
1213         args = {java.lang.String.class}
1214     )
1215     public void testCorrectReplacementBackreferencedJointSet() {
1216         Pattern pat = Pattern.compile("ab(a)*\\1");
1217         pat = Pattern.compile("abc(cd)fg");
1218         pat = Pattern.compile("aba*cd");
1219         pat = Pattern.compile("ab(a)*+cd");
1220         pat = Pattern.compile("ab(a)*?cd");
1221         pat = Pattern.compile("ab(a)+cd");
1222         pat = Pattern.compile(".*(.)\\1");
1223         pat = Pattern.compile("ab((a)|c|d)e");
1224         pat = Pattern.compile("abc((a(b))cd)");
1225         pat = Pattern.compile("ab(a)++cd");
1226         pat = Pattern.compile("ab(a)?(c)d");
1227         pat = Pattern.compile("ab(a)?+cd");
1228         pat = Pattern.compile("ab(a)??cd");
1229         pat = Pattern.compile("ab(a)??cd");
1230         pat = Pattern.compile("ab(a){1,3}?(c)d");
1231     }
1232
1233     @TestTargets({
1234         @TestTargetNew(
1235             level = TestLevel.PARTIAL_COMPLETE,
1236             notes = "Verifies the functionality of compile(java.lang.String) & matcher(java.lang.CharSequence) methods.",
1237             method = "compile",
1238             args = {java.lang.String.class}
1239         ),
1240         @TestTargetNew(
1241             level = TestLevel.PARTIAL_COMPLETE,
1242             notes = "Verifies the functionality of compile(java.lang.String) & matcher(java.lang.CharSequence) methods.",
1243             method = "matcher",
1244             args = {java.lang.CharSequence.class}
1245         )
1246     })
1247     public void testCompilePatternWithTerminatorMark() {
1248         Pattern pat = Pattern.compile("a\u0000\u0000cd");
1249         Matcher mat = pat.matcher("a\u0000\u0000cd");
1250         assertTrue(mat.matches());
1251     }
1252
1253     @TestTargets({
1254         @TestTargetNew(
1255             level = TestLevel.PARTIAL_COMPLETE,
1256             notes = "Verifies the functionality of compile(java.lang.String) & matcher(java.lang.CharSequence) methods.",
1257             method = "compile",
1258             args = {java.lang.String.class}
1259         ),
1260         @TestTargetNew(
1261             level = TestLevel.PARTIAL_COMPLETE,
1262             notes = "Verifies the functionality of compile(java.lang.String) & matcher(java.lang.CharSequence) methods.",
1263             method = "matcher",
1264             args = {java.lang.CharSequence.class}
1265         )
1266     })
1267     public void testAlternations() {
1268         String baseString = "|a|bc";
1269         Pattern pat = Pattern.compile(baseString);
1270         Matcher mat = pat.matcher("");
1271
1272         assertTrue(mat.matches());
1273
1274         baseString = "a||bc";
1275         pat = Pattern.compile(baseString);
1276         mat = pat.matcher("");
1277         assertTrue(mat.matches());
1278
1279         baseString = "a|bc|";
1280         pat = Pattern.compile(baseString);
1281         mat = pat.matcher("");
1282         assertTrue(mat.matches());
1283
1284         baseString = "a|b|";
1285         pat = Pattern.compile(baseString);
1286         mat = pat.matcher("");
1287         assertTrue(mat.matches());
1288
1289         baseString = "a(|b|cd)e";
1290         pat = Pattern.compile(baseString);
1291         mat = pat.matcher("ae");
1292         assertTrue(mat.matches());
1293
1294         baseString = "a(b||cd)e";
1295         pat = Pattern.compile(baseString);
1296         mat = pat.matcher("ae");
1297         assertTrue(mat.matches());
1298
1299         baseString = "a(b|cd|)e";
1300         pat = Pattern.compile(baseString);
1301         mat = pat.matcher("ae");
1302         assertTrue(mat.matches());
1303
1304         baseString = "a(b|c|)e";
1305         pat = Pattern.compile(baseString);
1306         mat = pat.matcher("ae");
1307         assertTrue(mat.matches());
1308
1309         baseString = "a(|)e";
1310         pat = Pattern.compile(baseString);
1311         mat = pat.matcher("ae");
1312         assertTrue(mat.matches());
1313
1314         baseString = "|";
1315         pat = Pattern.compile(baseString);
1316         mat = pat.matcher("");
1317         assertTrue(mat.matches());
1318
1319         baseString = "a(?:|)e";
1320         pat = Pattern.compile(baseString);
1321         mat = pat.matcher("ae");
1322         assertTrue(mat.matches());
1323
1324         baseString = "a||||bc";
1325         pat = Pattern.compile(baseString);
1326         mat = pat.matcher("");
1327         assertTrue(mat.matches());
1328
1329         baseString = "(?i-is)|a";
1330         pat = Pattern.compile(baseString);
1331         mat = pat.matcher("a");
1332         assertTrue(mat.matches());
1333     }
1334
1335     @TestTargets({
1336         @TestTargetNew(
1337             level = TestLevel.PARTIAL_COMPLETE,
1338             notes = "Verifies the functionality of compile(java.lang.String) & matcher(java.lang.CharSequence) methods.",
1339             method = "compile",
1340             args = {java.lang.String.class}
1341         ),
1342         @TestTargetNew(
1343             level = TestLevel.PARTIAL_COMPLETE,
1344             notes = "Verifies the functionality of compile(java.lang.String) & matcher(java.lang.CharSequence) methods.",
1345             method = "matcher",
1346             args = {java.lang.CharSequence.class}
1347         )
1348     })
1349     public void testMatchWithGroups() {
1350         String baseString = "jwkerhjwehrkwjehrkwjhrwkjehrjwkehrjkwhrkwehrkwhrkwrhwkhrwkjehr";
1351         String pattern = ".*(..).*\\1.*";
1352         assertTrue(Pattern.compile(pattern).matcher(baseString).matches());
1353
1354         baseString = "saa";
1355         pattern = ".*(.)\\1";
1356         assertTrue(Pattern.compile(pattern).matcher(baseString).matches());
1357         assertTrue(Pattern.compile(pattern).matcher(baseString).find());
1358     }
1359
1360     @TestTargetNew(
1361         level = TestLevel.PARTIAL_COMPLETE,
1362         notes = "Verifies split method for empty string.",
1363         method = "split",
1364         args = {java.lang.CharSequence.class}
1365     )
1366     public void testSplitEmptyCharSequence() {
1367         String s1 = "";
1368         String[] arr = s1.split(":");
1369         assertEquals(arr.length, 1);
1370     }
1371
1372     @TestTargets({
1373         @TestTargetNew(
1374             level = TestLevel.PARTIAL_COMPLETE,
1375             notes = "The test verifies the functionality of compile(java.lang.String) & split(java.lang.CharSequence, int) methods.",
1376             method = "compile",
1377             args = {java.lang.String.class}
1378         ),
1379         @TestTargetNew(
1380             level = TestLevel.PARTIAL_COMPLETE,
1381             notes = "The test verifies the functionality of compile(java.lang.String) & split(java.lang.CharSequence, int) methods.",
1382             method = "split",
1383             args = {java.lang.CharSequence.class, int.class}
1384         )
1385     })
1386     public void testSplitEndsWithPattern() {
1387         assertEquals(",,".split(",", 3).length, 3);
1388         assertEquals(",,".split(",", 4).length, 3);
1389
1390         assertEquals(Pattern.compile("o").split("boo:and:foo", 5).length, 5);
1391         assertEquals(Pattern.compile("b").split("ab", -1).length, 2);
1392     }
1393
1394     @TestTargetNew(
1395         level = TestLevel.PARTIAL_COMPLETE,
1396         notes = "The test verifies the functionality of matches(java.lang.String), java.lang.CharSequence) method for case insensitive flags.",
1397         method = "matches",
1398         args = {java.lang.String.class, java.lang.CharSequence.class}
1399     )
1400     public void testCaseInsensitiveFlag() {
1401         assertTrue(Pattern.matches("(?i-:AbC)", "ABC"));
1402     }
1403
1404     @TestTargets({
1405         @TestTargetNew(
1406             level = TestLevel.PARTIAL_COMPLETE,
1407             notes = "Verifies the functionality of compile(java.lang.String) & matcher(java.lang.CharSequence) methods.",
1408             method = "compile",
1409             args = {java.lang.String.class}
1410         ),
1411         @TestTargetNew(
1412             level = TestLevel.PARTIAL_COMPLETE,
1413             notes = "Verifies the functionality of compile(java.lang.String) & matcher(java.lang.CharSequence) methods.",
1414             method = "matcher",
1415             args = {java.lang.CharSequence.class}
1416         )
1417     })
1418     public void testEmptyGroups() {
1419         Pattern pat = Pattern.compile("ab(?>)cda");
1420         Matcher mat = pat.matcher("abcda");
1421         assertTrue(mat.matches());
1422
1423         pat = Pattern.compile("ab()");
1424         mat = pat.matcher("ab");
1425         assertTrue(mat.matches());
1426
1427         pat = Pattern.compile("abc(?:)(..)");
1428         mat = pat.matcher("abcgf");
1429         assertTrue(mat.matches());
1430     }
1431
1432     @TestTargets({
1433         @TestTargetNew(
1434             level = TestLevel.PARTIAL_COMPLETE,
1435             notes = "Verifies the functionality of compile(java.lang.String) & compile(java.lang.String, int) methods.",
1436             method = "compile",
1437             args = {java.lang.String.class}
1438         ),
1439         @TestTargetNew(
1440             level = TestLevel.PARTIAL_COMPLETE,
1441             notes = "Verifies the functionality of compile(java.lang.String) & compile(java.lang.String, int) methods.",
1442             method = "compile",
1443             args = {java.lang.String.class, int.class}
1444         )
1445     })
1446     public void testCompileNonCaptGroup() {
1447         boolean isCompiled = false;
1448
1449         try {
1450 // BEGIN android-change
1451 // We don't have canonical equivalence.
1452             Pattern pat = Pattern.compile("(?:)");
1453             pat = Pattern.compile("(?:)", Pattern.DOTALL);
1454             pat = Pattern.compile("(?:)", Pattern.CASE_INSENSITIVE);
1455             pat = Pattern.compile("(?:)", Pattern.COMMENTS | Pattern.UNIX_LINES);
1456 // END android-change
1457             isCompiled = true;
1458         } catch (PatternSyntaxException e) {
1459             System.out.println(e);
1460         }
1461         assertTrue(isCompiled);
1462     }
1463
1464     @TestTargets({
1465         @TestTargetNew(
1466             level = TestLevel.PARTIAL_COMPLETE,
1467             notes = "Verifies the functionality of compile(java.lang.String) & matcher(java.lang.CharSequence) methods.",
1468             method = "compile",
1469             args = {java.lang.String.class}
1470         ),
1471         @TestTargetNew(
1472             level = TestLevel.PARTIAL_COMPLETE,
1473             notes = "Verifies the functionality of compile(java.lang.String) & matcher(java.lang.CharSequence) methods.",
1474             method = "matcher",
1475             args = {java.lang.CharSequence.class}
1476         )
1477     })
1478     public void testEmbeddedFlags() {
1479         String baseString = "(?i)((?s)a)";
1480         String testString = "A";
1481         Pattern pat = Pattern.compile(baseString);
1482         Matcher mat = pat.matcher(testString);
1483         assertTrue(mat.matches());
1484
1485         baseString = "(?x)(?i)(?s)(?d)a";
1486         testString = "A";
1487         pat = Pattern.compile(baseString);
1488         mat = pat.matcher(testString);
1489         assertTrue(mat.matches());
1490
1491         baseString = "(?x)(?i)(?s)(?d)a.";
1492         testString = "a\n";
1493         pat = Pattern.compile(baseString);
1494         mat = pat.matcher(testString);
1495         assertTrue(mat.matches());
1496
1497         baseString = "abc(?x:(?i)(?s)(?d)a.)";
1498         testString = "abcA\n";
1499         pat = Pattern.compile(baseString);
1500         mat = pat.matcher(testString);
1501         assertTrue(mat.matches());
1502
1503         baseString = "abc((?x)d)(?i)(?s)a";
1504         testString = "abcdA";
1505         pat = Pattern.compile(baseString);
1506         mat = pat.matcher(testString);
1507         assertTrue(mat.matches());
1508     }
1509
1510     @TestTargetNew(
1511         level = TestLevel.PARTIAL_COMPLETE,
1512         notes = "Verifies the functionality of compile(java.lang.String) method.",
1513         method = "compile",
1514         args = {java.lang.String.class}
1515     )
1516     public void testAltWithFlags() {
1517         boolean isCompiled = false;
1518
1519         try {
1520             Pattern pat = Pattern.compile("|(?i-xi)|()");
1521             isCompiled = true;
1522         } catch (PatternSyntaxException e) {
1523             System.out.println(e);
1524         }
1525         assertTrue(isCompiled);
1526     }
1527
1528     @TestTargets({
1529         @TestTargetNew(
1530             level = TestLevel.PARTIAL_COMPLETE,
1531             notes = "Verifies the functionality of compile(java.lang.String) & matcher(java.lang.CharSequence) methods.",
1532             method = "compile",
1533             args = {java.lang.String.class}
1534         ),
1535         @TestTargetNew(
1536             level = TestLevel.PARTIAL_COMPLETE,
1537             notes = "Verifies the functionality of compile(java.lang.String) & matcher(java.lang.CharSequence) methods.",
1538             method = "matcher",
1539             args = {java.lang.CharSequence.class}
1540         )
1541     })
1542 public void testRestoreFlagsAfterGroup() {
1543         String baseString = "abc((?x)d)   a";
1544         String testString = "abcd   a";
1545         Pattern pat = Pattern.compile(baseString);
1546         Matcher mat = pat.matcher(testString);
1547
1548         assertTrue(mat.matches());
1549     }
1550
1551     /*
1552      * Verify if the Pattern support the following character classes:
1553      * \p{javaLowerCase} \p{javaUpperCase} \p{javaWhitespace} \p{javaMirrored}
1554      */
1555     @TestTargetNew(
1556         level = TestLevel.PARTIAL_COMPLETE,
1557         notes = "Verifies the functionality of compile(java.lang.String) method.",
1558         method = "compile",
1559         args = {java.lang.String.class}
1560     )
1561     public void testCompileCharacterClass() {
1562         // Regression for HARMONY-606, 696
1563         Pattern pattern = Pattern.compile("\\p{javaLowerCase}");
1564         assertNotNull(pattern);
1565
1566         pattern = Pattern.compile("\\p{javaUpperCase}");
1567         assertNotNull(pattern);
1568
1569         pattern = Pattern.compile("\\p{javaWhitespace}");
1570         assertNotNull(pattern);
1571
1572         pattern = Pattern.compile("\\p{javaMirrored}");
1573         assertNotNull(pattern);
1574
1575         pattern = Pattern.compile("\\p{javaDefined}");
1576         assertNotNull(pattern);
1577
1578         pattern = Pattern.compile("\\p{javaDigit}");
1579         assertNotNull(pattern);
1580
1581         pattern = Pattern.compile("\\p{javaIdentifierIgnorable}");
1582         assertNotNull(pattern);
1583
1584         pattern = Pattern.compile("\\p{javaISOControl}");
1585         assertNotNull(pattern);
1586
1587         pattern = Pattern.compile("\\p{javaJavaIdentifierPart}");
1588         assertNotNull(pattern);
1589
1590         pattern = Pattern.compile("\\p{javaJavaIdentifierStart}");
1591         assertNotNull(pattern);
1592
1593         pattern = Pattern.compile("\\p{javaLetter}");
1594         assertNotNull(pattern);
1595
1596         pattern = Pattern.compile("\\p{javaLetterOrDigit}");
1597         assertNotNull(pattern);
1598
1599         pattern = Pattern.compile("\\p{javaSpaceChar}");
1600         assertNotNull(pattern);
1601
1602         pattern = Pattern.compile("\\p{javaTitleCase}");
1603         assertNotNull(pattern);
1604
1605         pattern = Pattern.compile("\\p{javaUnicodeIdentifierPart}");
1606         assertNotNull(pattern);
1607
1608         pattern = Pattern.compile("\\p{javaUnicodeIdentifierStart}");
1609         assertNotNull(pattern);
1610     }
1611
1612     /**
1613      * s original test was fixed to pass on RI
1614      */
1615
1616 // BEGIN android-removed
1617 // We don't have canonical equivalence.
1618 //    public void testCanonEqFlag() {
1619 //
1620 //        /*
1621 //         * for decompositions see
1622 //         * http://www.unicode.org/Public/4.0-Update/UnicodeData-4.0.0.txt
1623 //         * http://www.unicode.org/reports/tr15/#Decomposition
1624 //         */
1625 //        String baseString;
1626 //        String testString;
1627 //        Pattern pat;
1628 //        Matcher mat;
1629 //
1630 //        baseString = "ab(a*)\\1";
1631 //        pat = Pattern.compile(baseString, Pattern.CANON_EQ);
1632 //
1633 //        baseString = "a(abcdf)d";
1634 //        pat = Pattern.compile(baseString, Pattern.CANON_EQ);
1635 //
1636 //        baseString = "aabcdfd";
1637 //        pat = Pattern.compile(baseString, Pattern.CANON_EQ);
1638 //
1639 //        // \u01E0 -> \u0226\u0304 ->\u0041\u0307\u0304
1640 //        // \u00CC -> \u0049\u0300
1641 //
1642 //        /*
1643 //         * baseString = "\u01E0\u00CCcdb(ac)"; testString =
1644 //         * "\u0226\u0304\u0049\u0300cdbac"; pat = Pattern.compile(baseString,
1645 //         * Pattern.CANON_EQ); mat = pat.matcher(testString);
1646 //         * assertTrue(mat.matches());
1647 //         */
1648 //        baseString = "\u01E0cdb(a\u00CCc)";
1649 //        testString = "\u0041\u0307\u0304cdba\u0049\u0300c";
1650 //        pat = Pattern.compile(baseString, Pattern.CANON_EQ);
1651 //        mat = pat.matcher(testString);
1652 //        assertTrue(mat.matches());
1653 //
1654 //        baseString = "a\u00CC";
1655 //        testString = "a\u0049\u0300";
1656 //        pat = Pattern.compile(baseString, Pattern.CANON_EQ);
1657 //        mat = pat.matcher(testString);
1658 //        assertTrue(mat.matches());
1659 //
1660 //        /*
1661 //         * baseString = "\u0226\u0304cdb(ac\u0049\u0300)"; testString =
1662 //         * "\u01E0cdbac\u00CC"; pat = Pattern.compile(baseString,
1663 //         * Pattern.CANON_EQ); mat = pat.matcher(testString);
1664 //         * assertTrue(mat.matches());
1665 //         *
1666 //         * baseString = "cdb(?:\u0041\u0307\u0304\u00CC)"; testString =
1667 //         * "cdb\u0226\u0304\u0049\u0300"; pat = Pattern.compile(baseString,
1668 //         * Pattern.CANON_EQ); mat = pat.matcher(testString);
1669 //         * assertTrue(mat.matches());
1670 //         *
1671 //         * baseString = "\u01E0[a-c]\u0049\u0300cdb(ac)"; testString =
1672 //         * "\u01E0b\u00CCcdbac"; pat = Pattern.compile(baseString,
1673 //         * Pattern.CANON_EQ); mat = pat.matcher(testString);
1674 //         * assertTrue(mat.matches());
1675 //         *
1676 //         * baseString = "\u01E0|\u00CCcdb(ac)"; testString =
1677 //         * "\u0041\u0307\u0304"; pat = Pattern.compile(baseString,
1678 //         * Pattern.CANON_EQ); mat = pat.matcher(testString);
1679 //         * assertTrue(mat.matches());
1680 //         *
1681 //         * baseString = "\u00CC?cdb(ac)*(\u01E0)*[a-c]"; testString =
1682 //         * "cdb\u0041\u0307\u0304b"; pat = Pattern.compile(baseString,
1683 //         * Pattern.CANON_EQ); mat = pat.matcher(testString);
1684 //         * assertTrue(mat.matches());
1685 //         */
1686 //        baseString = "a\u0300";
1687 //        pat = Pattern.compile(baseString, Pattern.CANON_EQ);
1688 //        mat = pat.matcher("a\u00E0a");
1689 //        assertTrue(mat.find());
1690 //
1691 //        /*
1692 //         * baseString = "\u7B20\uF9F8abc"; pat = Pattern.compile(baseString,
1693 //         * Pattern.CANON_EQ); mat = pat.matcher("\uF9F8\uF9F8abc");
1694 //         * assertTrue(mat.matches());
1695 //         *
1696 //         * //\u01F9 -> \u006E\u0300 //\u00C3 -> \u0041\u0303
1697 //         *
1698 //         * baseString = "cdb(?:\u00C3\u006E\u0300)"; testString =
1699 //         * "cdb\u0041\u0303\u01F9"; pat = Pattern.compile(baseString,
1700 //         * Pattern.CANON_EQ); mat = pat.matcher(testString);
1701 //         * assertTrue(mat.matches());
1702 //         *
1703 //         * //\u014C -> \u004F\u0304 //\u0163 -> \u0074\u0327
1704 //         *
1705 //         * baseString = "cdb(?:\u0163\u004F\u0304)"; testString =
1706 //         * "cdb\u0074\u0327\u014C"; pat = Pattern.compile(baseString,
1707 //         * Pattern.CANON_EQ); mat = pat.matcher(testString);
1708 //         * assertTrue(mat.matches());
1709 //         */
1710 //        // \u00E1->a\u0301
1711 //        // canonical ordering takes place \u0301\u0327 -> \u0327\u0301
1712 //        baseString = "c\u0327\u0301";
1713 //        testString = "c\u0301\u0327";
1714 //        pat = Pattern.compile(baseString, Pattern.CANON_EQ);
1715 //        mat = pat.matcher(testString);
1716 //        assertTrue(mat.matches());
1717 //
1718 //        /*
1719 //         * Hangul decompositions
1720 //         */
1721 //        // \uD4DB->\u1111\u1171\u11B6
1722 //        // \uD21E->\u1110\u116D\u11B5
1723 //        // \uD264->\u1110\u1170
1724 //        // not Hangul:\u0453->\u0433\u0301
1725 //        baseString = "a\uD4DB\u1111\u1171\u11B6\uD264";
1726 //        pat = Pattern.compile(baseString, Pattern.CANON_EQ);
1727 //
1728 //        baseString = "\u0453c\uD4DB";
1729 //        pat = Pattern.compile(baseString, Pattern.CANON_EQ);
1730 //
1731 //        baseString = "a\u1110\u116D\u11B5b\uD21Ebc";
1732 //        pat = Pattern.compile(baseString, Pattern.CANON_EQ);
1733 //
1734 //        /*
1735 //         * baseString = "\uD4DB\uD21E\u1110\u1170cdb(ac)"; testString =
1736 //         * "\u1111\u1171\u11B6\u1110\u116D\u11B5\uD264cdbac"; pat =
1737 //         * Pattern.compile(baseString, Pattern.CANON_EQ); mat =
1738 //         * pat.matcher(testString); assertTrue(mat.matches());
1739 //         */
1740 //        baseString = "\uD4DB\uD264cdb(a\uD21Ec)";
1741 //        testString = "\u1111\u1171\u11B6\u1110\u1170cdba\u1110\u116D\u11B5c";
1742 //        pat = Pattern.compile(baseString, Pattern.CANON_EQ);
1743 //        mat = pat.matcher(testString);
1744 //        assertTrue(mat.matches());
1745 //
1746 //        baseString = "a\uD4DB";
1747 //        testString = "a\u1111\u1171\u11B6";
1748 //        pat = Pattern.compile(baseString, Pattern.CANON_EQ);
1749 //        mat = pat.matcher(testString);
1750 //        assertTrue(mat.matches());
1751 //
1752 //        baseString = "a\uD21E";
1753 //        testString = "a\u1110\u116D\u11B5";
1754 //        pat = Pattern.compile(baseString, Pattern.CANON_EQ);
1755 //        mat = pat.matcher(testString);
1756 //        assertTrue(mat.matches());
1757 //
1758 //        /*
1759 //         * baseString = "\u1111\u1171\u11B6cdb(ac\u1110\u116D\u11B5)";
1760 //         * testString = "\uD4DBcdbac\uD21E"; pat = Pattern.compile(baseString,
1761 //         * Pattern.CANON_EQ); mat = pat.matcher(testString);
1762 //         * assertTrue(mat.matches());
1763 //         *
1764 //         * baseString = "cdb(?:\u1111\u1171\u11B6\uD21E)"; testString =
1765 //         * "cdb\uD4DB\u1110\u116D\u11B5"; pat = Pattern.compile(baseString,
1766 //         * Pattern.CANON_EQ); mat = pat.matcher(testString);
1767 //         * assertTrue(mat.matches());
1768 //         *
1769 //         * baseString = "\uD4DB[a-c]\u1110\u116D\u11B5cdb(ac)"; testString =
1770 //         * "\uD4DBb\uD21Ecdbac"; pat = Pattern.compile(baseString,
1771 //         * Pattern.CANON_EQ); mat = pat.matcher(testString);
1772 //         * assertTrue(mat.matches());
1773 //         */
1774 //        baseString = "\uD4DB|\u00CCcdb(ac)";
1775 //        testString = "\u1111\u1171\u11B6";
1776 //        pat = Pattern.compile(baseString, Pattern.CANON_EQ);
1777 //        mat = pat.matcher(testString);
1778 //        assertTrue(mat.matches());
1779 //
1780 //        baseString = "\uD4DB|\u00CCcdb(ac)";
1781 //        testString = "\u1111\u1171";
1782 //        pat = Pattern.compile(baseString, Pattern.CANON_EQ);
1783 //        mat = pat.matcher(testString);
1784 //        assertFalse(mat.matches());
1785 //
1786 //        baseString = "\u00CC?cdb(ac)*(\uD4DB)*[a-c]";
1787 //        testString = "cdb\u1111\u1171\u11B6b";
1788 //        pat = Pattern.compile(baseString, Pattern.CANON_EQ);
1789 //        mat = pat.matcher(testString);
1790 //        assertTrue(mat.matches());
1791 //
1792 //        baseString = "\uD4DB";
1793 //        pat = Pattern.compile(baseString, Pattern.CANON_EQ);
1794 //        mat = pat.matcher("a\u1111\u1171\u11B6a");
1795 //        assertTrue(mat.find());
1796 //
1797 //        baseString = "\u1111";
1798 //        pat = Pattern.compile(baseString, Pattern.CANON_EQ);
1799 //        mat = pat.matcher("bcda\uD4DBr");
1800 //        assertFalse(mat.find());
1801 //    }
1802 //
1803 //    /**
1804 //     * s original test was fixed to pass on RI
1805 //     */
1806 //
1807 //    public void testIndexesCanonicalEq() {
1808 //        String baseString;
1809 //        String testString;
1810 //        Pattern pat;
1811 //        Matcher mat;
1812 //
1813 //        baseString = "\uD4DB";
1814 //        pat = Pattern.compile(baseString, Pattern.CANON_EQ);
1815 //        mat = pat.matcher("bcda\u1111\u1171\u11B6awr");
1816 //        assertTrue(mat.find());
1817 //        assertEquals(mat.start(), 4);
1818 //        assertEquals(mat.end(), 7);
1819 //
1820 //        /*
1821 //         * baseString = "\uD4DB\u1111\u1171\u11B6"; pat =
1822 //         * Pattern.compile(baseString, Pattern.CANON_EQ); mat =
1823 //         * pat.matcher("bcda\u1111\u1171\u11B6\uD4DBawr");
1824 //         * assertTrue(mat.find()); assertEquals(mat.start(), 4);
1825 //         * assertEquals(mat.end(), 8);
1826 //         *
1827 //         * baseString = "\uD4DB\uD21E\u1110\u1170"; testString =
1828 //         * "abcabc\u1111\u1171\u11B6\u1110\u116D\u11B5\uD264cdbac"; pat =
1829 //         * Pattern.compile(baseString, Pattern.CANON_EQ); mat =
1830 //         * pat.matcher(testString); assertTrue(mat.find());
1831 //         * assertEquals(mat.start(), 6); assertEquals(mat.end(), 13);
1832 //         */}
1833 //
1834 //    /**
1835 //     * s original test was fixed to pass on RI
1836 //     */
1837 //
1838 //    public void testCanonEqFlagWithSupplementaryCharacters() {
1839 //
1840 //        /*
1841 //         * \u1D1BF->\u1D1BB\u1D16F->\u1D1B9\u1D165\u1D16F in UTF32
1842 //         * \uD834\uDDBF->\uD834\uDDBB\uD834\uDD6F
1843 //         * ->\uD834\uDDB9\uD834\uDD65\uD834\uDD6F in UTF16
1844 //         */
1845 //        String patString = "abc\uD834\uDDBFef";
1846 //        String testString = "abc\uD834\uDDB9\uD834\uDD65\uD834\uDD6Fef";
1847 //        Pattern pat = Pattern.compile(patString, Pattern.CANON_EQ);
1848 //        Matcher mat = pat.matcher(testString);
1849 //        assertTrue(mat.matches());
1850 //        /*
1851 //         * testString = "abc\uD834\uDDBB\uD834\uDD6Fef"; mat =
1852 //         * pat.matcher(testString); assertTrue(mat.matches());
1853 //         *
1854 //         * patString = "abc\uD834\uDDBB\uD834\uDD6Fef"; testString =
1855 //         * "abc\uD834\uDDBFef"; pat = Pattern.compile(patString,
1856 //         * Pattern.CANON_EQ); mat = pat.matcher(testString);
1857 //         * assertTrue(mat.matches());
1858 //         */
1859 //        testString = "abc\uD834\uDDB9\uD834\uDD65\uD834\uDD6Fef";
1860 //        mat = pat.matcher(testString);
1861 //        assertTrue(mat.matches());
1862 //        /*
1863 //         * patString = "abc\uD834\uDDB9\uD834\uDD65\uD834\uDD6Fef"; testString =
1864 //         * "abc\uD834\uDDBFef"; pat = Pattern.compile(patString,
1865 //         * Pattern.CANON_EQ); mat = pat.matcher(testString);
1866 //         * assertTrue(mat.matches());
1867 //         *
1868 //         * testString = "abc\uD834\uDDBB\uD834\uDD6Fef"; mat =
1869 //         * pat.matcher(testString); assertTrue(mat.matches());
1870 //         */
1871 //        /*
1872 //         * testSupplementary characters with no decomposition
1873 //         */
1874 //        /*
1875 //         * patString = "a\uD9A0\uDE8Ebc\uD834\uDDBB\uD834\uDD6Fe\uDE8Ef";
1876 //         * testString = "a\uD9A0\uDE8Ebc\uD834\uDDBFe\uDE8Ef"; pat =
1877 //         * Pattern.compile(patString, Pattern.CANON_EQ); mat =
1878 //         * pat.matcher(testString); assertTrue(mat.matches());
1879 //         */}
1880 // END android-removed
1881
1882     @TestTargets({
1883         @TestTargetNew(
1884             level = TestLevel.PARTIAL_COMPLETE,
1885             notes = "Verifies the functionality of compile(java.lang.String) & matcher(java.lang.CharSequence) methods.",
1886             method = "compile",
1887             args = {java.lang.String.class}
1888         ),
1889         @TestTargetNew(
1890             level = TestLevel.PARTIAL_COMPLETE,
1891             notes = "Verifies the functionality of compile(java.lang.String) & matcher(java.lang.CharSequence) methods.",
1892             method = "matcher",
1893             args = {java.lang.CharSequence.class}
1894         )
1895     })
1896     public void testRangesWithSurrogatesSupplementary() {
1897         String patString = "[abc\uD8D2]";
1898         String testString = "\uD8D2";
1899         Pattern pat = Pattern.compile(patString);
1900         Matcher mat = pat.matcher(testString);
1901         assertTrue(mat.matches());
1902
1903         testString = "a";
1904         mat = pat.matcher(testString);
1905         assertTrue(mat.matches());
1906
1907         testString = "ef\uD8D2\uDD71gh";
1908         mat = pat.matcher(testString);
1909         assertFalse(mat.find());
1910
1911         testString = "ef\uD8D2gh";
1912         mat = pat.matcher(testString);
1913         assertTrue(mat.find());
1914
1915         patString = "[abc\uD8D3&&[c\uD8D3]]";
1916         testString = "c";
1917         pat = Pattern.compile(patString);
1918         mat = pat.matcher(testString);
1919         assertTrue(mat.matches());
1920
1921         testString = "a";
1922         mat = pat.matcher(testString);
1923         assertFalse(mat.matches());
1924
1925         testString = "ef\uD8D3\uDD71gh";
1926         mat = pat.matcher(testString);
1927         assertFalse(mat.find());
1928
1929         testString = "ef\uD8D3gh";
1930         mat = pat.matcher(testString);
1931         assertTrue(mat.find());
1932
1933         patString = "[abc\uD8D3\uDBEE\uDF0C&&[c\uD8D3\uDBEE\uDF0C]]";
1934         testString = "c";
1935         pat = Pattern.compile(patString);
1936         mat = pat.matcher(testString);
1937         assertTrue(mat.matches());
1938
1939         testString = "\uDBEE\uDF0C";
1940         mat = pat.matcher(testString);
1941         assertTrue(mat.matches());
1942
1943         testString = "ef\uD8D3\uDD71gh";
1944         mat = pat.matcher(testString);
1945         assertFalse(mat.find());
1946
1947         testString = "ef\uD8D3gh";
1948         mat = pat.matcher(testString);
1949         assertTrue(mat.find());
1950
1951         patString = "[abc\uDBFC]\uDDC2cd";
1952         testString = "\uDBFC\uDDC2cd";
1953         pat = Pattern.compile(patString);
1954         mat = pat.matcher(testString);
1955         assertFalse(mat.matches());
1956
1957         testString = "a\uDDC2cd";
1958         mat = pat.matcher(testString);
1959         assertTrue(mat.matches());
1960     }
1961
1962     @TestTargets({
1963         @TestTargetNew(
1964             level = TestLevel.PARTIAL_COMPLETE,
1965             notes = "Verifies the functionality of compile(java.lang.String) & matcher(java.lang.CharSequence) methods.",
1966             method = "compile",
1967             args = {java.lang.String.class}
1968         ),
1969         @TestTargetNew(
1970             level = TestLevel.PARTIAL_COMPLETE,
1971             notes = "Verifies the functionality of compile(java.lang.String) & matcher(java.lang.CharSequence) methods.",
1972             method = "matcher",
1973             args = {java.lang.CharSequence.class}
1974         )
1975     })
1976     public void testSequencesWithSurrogatesSupplementary() {
1977         String patString = "abcd\uD8D3";
1978         String testString = "abcd\uD8D3\uDFFC";
1979         Pattern pat = Pattern.compile(patString);
1980         Matcher mat = pat.matcher(testString);
1981 // BEGIN android-changed
1982 // This one really doesn't make sense, as the above is a corrupt surrogate.
1983 // Even if it's matched by the JDK, it's more of a bug than of a behavior one
1984 // might want to duplicate.
1985 //        assertFalse(mat.find());
1986 // END android-changed
1987         testString = "abcd\uD8D3abc";
1988         mat = pat.matcher(testString);
1989         assertTrue(mat.find());
1990
1991         patString = "ab\uDBEFcd";
1992         testString = "ab\uDBEFcd";
1993         pat = Pattern.compile(patString);
1994         mat = pat.matcher(testString);
1995         assertTrue(mat.matches());
1996
1997         patString = "\uDFFCabcd";
1998         testString = "\uD8D3\uDFFCabcd";
1999         pat = Pattern.compile(patString);
2000         mat = pat.matcher(testString);
2001         assertFalse(mat.find());
2002
2003         testString = "abc\uDFFCabcdecd";
2004         mat = pat.matcher(testString);
2005         assertTrue(mat.find());
2006
2007         patString = "\uD8D3\uDFFCabcd";
2008         testString = "abc\uD8D3\uD8D3\uDFFCabcd";
2009         pat = Pattern.compile(patString);
2010         mat = pat.matcher(testString);
2011         assertTrue(mat.find());
2012     }
2013
2014     /**
2015      * s original test was fixed to pass on RI
2016      */
2017
2018     @TestTargets({
2019         @TestTargetNew(
2020             level = TestLevel.PARTIAL_COMPLETE,
2021             notes = "Verifies the functionality of compile(java.lang.String) & matcher(java.lang.CharSequence) methods.",
2022             method = "compile",
2023             args = {java.lang.String.class}
2024         ),
2025         @TestTargetNew(
2026             level = TestLevel.PARTIAL_COMPLETE,
2027             notes = "Verifies the functionality of compile(java.lang.String) & matcher(java.lang.CharSequence) methods.",
2028             method = "matcher",
2029             args = {java.lang.CharSequence.class}
2030         )
2031     })
2032     public void testPredefinedClassesWithSurrogatesSupplementary() {
2033         String patString = "[123\\D]";
2034         String testString = "a";
2035         Pattern pat = Pattern.compile(patString);
2036         Matcher mat = pat.matcher(testString);
2037         assertTrue(mat.find());
2038
2039         testString = "5";
2040         mat = pat.matcher(testString);
2041         assertFalse(mat.find());
2042
2043         testString = "3";
2044         mat = pat.matcher(testString);
2045         assertTrue(mat.find());
2046
2047         // low surrogate
2048         testString = "\uDFC4";
2049         mat = pat.matcher(testString);
2050         assertTrue(mat.find());
2051
2052         // high surrogate
2053         testString = "\uDADA";
2054         mat = pat.matcher(testString);
2055         assertTrue(mat.find());
2056
2057         testString = "\uDADA\uDFC4";
2058         mat = pat.matcher(testString);
2059         assertTrue(mat.find());
2060
2061         patString = "[123[^\\p{javaDigit}]]";
2062         testString = "a";
2063         pat = Pattern.compile(patString);
2064         mat = pat.matcher(testString);
2065         assertTrue(mat.find());
2066
2067         testString = "5";
2068         mat = pat.matcher(testString);
2069         assertFalse(mat.find());
2070
2071         testString = "3";
2072         mat = pat.matcher(testString);
2073         assertTrue(mat.find());
2074
2075         // low surrogate
2076         testString = "\uDFC4";
2077         mat = pat.matcher(testString);
2078         assertTrue(mat.find());
2079
2080         // high surrogate
2081         testString = "\uDADA";
2082         mat = pat.matcher(testString);
2083         assertTrue(mat.find());
2084
2085         testString = "\uDADA\uDFC4";
2086         mat = pat.matcher(testString);
2087         assertTrue(mat.find());
2088
2089         // surrogate characters
2090         patString = "\\p{Cs}";
2091         testString = "\uD916\uDE27";
2092         pat = Pattern.compile(patString);
2093         mat = pat.matcher(testString);
2094
2095         /*
2096          * see http://www.unicode.org/reports/tr18/#Supplementary_Characters we
2097          * have to treat text as code points not code units. \\p{Cs} matches any
2098          * surrogate character but here testString is a one code point
2099          * consisting of two code units (two surrogate characters) so we find
2100          * nothing
2101          */
2102         // assertFalse(mat.find());
2103         // swap low and high surrogates
2104         testString = "\uDE27\uD916";
2105         mat = pat.matcher(testString);
2106         assertTrue(mat.find());
2107
2108         patString = "[\uD916\uDE271\uD91623&&[^\\p{Cs}]]";
2109         testString = "1";
2110         pat = Pattern.compile(patString);
2111         mat = pat.matcher(testString);
2112         assertTrue(mat.find());
2113
2114         testString = "\uD916";
2115         pat = Pattern.compile(patString);
2116         mat = pat.matcher(testString);
2117         assertFalse(mat.find());
2118
2119         testString = "\uD916\uDE27";
2120         pat = Pattern.compile(patString);
2121         mat = pat.matcher(testString);
2122         assertTrue(mat.find());
2123
2124         // \uD9A0\uDE8E=\u7828E
2125         // \u78281=\uD9A0\uDE81
2126         patString = "[a-\uD9A0\uDE8E]";
2127         testString = "\uD9A0\uDE81";
2128         pat = Pattern.compile(patString);
2129         mat = pat.matcher(testString);
2130         assertTrue(mat.matches());
2131     }
2132
2133     @TestTargets({
2134         @TestTargetNew(
2135             level = TestLevel.PARTIAL_COMPLETE,
2136             notes = "Verifies the functionality of compile(java.lang.String) &  compile(java.lang.String, int) matcher(java.lang.CharSequence) methods.",
2137             method = "compile",
2138             args = {java.lang.String.class}
2139         ),
2140         @TestTargetNew(
2141             level = TestLevel.PARTIAL_COMPLETE,
2142             notes = "Verifies the functionality of compile(java.lang.String) &  compile(java.lang.String, int) matcher(java.lang.CharSequence) methods.",
2143             method = "compile",
2144             args = {java.lang.String.class, int.class}
2145         ),
2146         @TestTargetNew(
2147             level = TestLevel.PARTIAL_COMPLETE,
2148             notes = "Verifies the functionality of compile(java.lang.String) &  compile(java.lang.String, int) matcher(java.lang.CharSequence) methods.",
2149             method = "matcher",
2150             args = {java.lang.CharSequence.class}
2151         )
2152     })
2153     public void testDotConstructionWithSurrogatesSupplementary() {
2154         String patString = ".";
2155         String testString = "\uD9A0\uDE81";
2156         Pattern pat = Pattern.compile(patString);
2157         Matcher mat = pat.matcher(testString);
2158         assertTrue(mat.matches());
2159
2160         testString = "\uDE81";
2161         mat = pat.matcher(testString);
2162         assertTrue(mat.matches());
2163
2164         testString = "\uD9A0";
2165         mat = pat.matcher(testString);
2166         assertTrue(mat.matches());
2167
2168         testString = "\n";
2169         mat = pat.matcher(testString);
2170         assertFalse(mat.matches());
2171
2172         patString = ".*\uDE81";
2173         testString = "\uD9A0\uDE81\uD9A0\uDE81\uD9A0\uDE81";
2174         pat = Pattern.compile(patString);
2175         mat = pat.matcher(testString);
2176         assertFalse(mat.matches());
2177
2178         testString = "\uD9A0\uDE81\uD9A0\uDE81\uDE81";
2179         mat = pat.matcher(testString);
2180         assertTrue(mat.matches());
2181
2182         patString = ".*";
2183         testString = "\uD9A0\uDE81\n\uD9A0\uDE81\uD9A0\n\uDE81";
2184         pat = Pattern.compile(patString, Pattern.DOTALL);
2185         mat = pat.matcher(testString);
2186         assertTrue(mat.matches());
2187     }
2188
2189     /**
2190      * s java.util.regex.Pattern.quote(String)
2191      */
2192     @TestTargetNew(
2193         level = TestLevel.COMPLETE,
2194         notes = "",
2195         method = "quote",
2196         args = {java.lang.String.class}
2197     )
2198     public void test_quoteLjava_lang_String() {
2199         for (String aPattern : testPatterns) {
2200             Pattern p = Pattern.compile(aPattern);
2201             try {
2202                 assertEquals("quote was wrong for plain text", "\\Qtest\\E", p
2203                         .quote("test"));
2204                 assertEquals("quote was wrong for text with quote sign",
2205                         "\\Q\\Qtest\\E", p.quote("\\Qtest"));
2206                 assertEquals("quote was wrong for quotted text",
2207                         "\\Q\\Qtest\\E\\\\E\\Q\\E", p.quote("\\Qtest\\E"));
2208             } catch (Exception e) {
2209                 fail("Unexpected exception: " + e);
2210             }
2211         }
2212     }
2213
2214     /**
2215      * s java.util.regex.Pattern.matcher(String, CharSequence)
2216      * coped from test for matches method
2217      */
2218
2219     @TestTargets({
2220         @TestTargetNew(
2221             level = TestLevel.PARTIAL_COMPLETE,
2222             notes = "Verifies the functionality of compile(java.lang.String) & matcher(java.lang.CharSequence) methods.",
2223             method = "compile",
2224             args = {java.lang.String.class}
2225         ),
2226         @TestTargetNew(
2227             level = TestLevel.PARTIAL_COMPLETE,
2228             notes = "Verifies the functionality of compile(java.lang.String) & matcher(java.lang.CharSequence) methods.",
2229             method = "matcher",
2230             args = {java.lang.CharSequence.class}
2231         )
2232     })
2233     public void test_matcherLjava_lang_StringLjava_lang_CharSequence() {
2234         String[][] posSeq = {
2235                 { "abb", "ababb", "abababbababb", "abababbababbabababbbbbabb" },
2236                 { "213567", "12324567", "1234567", "213213567",
2237                         "21312312312567", "444444567" },
2238                 { "abcdaab", "aab", "abaab", "cdaab", "acbdadcbaab" },
2239                 { "213234567", "3458", "0987654", "7689546432", "0398576",
2240                         "98432", "5" },
2241                 {
2242                         "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
2243                         "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
2244                                 + "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" },
2245                 { "ababbaAabababblice", "ababbaAliceababab", "ababbAabliceaaa",
2246                         "abbbAbbbliceaaa", "Alice" },
2247                 { "a123", "bnxnvgds156", "for", "while", "if", "struct" },
2248                 { "xy" }, { "xy" }, { "xcy" }
2249
2250         };
2251
2252         for (int i = 0; i < testPatterns.length; i++) {
2253             for (int j = 0; j < posSeq[i].length; j++) {
2254                 assertTrue("Incorrect match: " + testPatterns[i] + " vs "
2255                         + posSeq[i][j], Pattern.compile(testPatterns[i])
2256                         .matcher(posSeq[i][j]).matches());
2257             }
2258         }
2259     }
2260
2261     @TestTargets({
2262         @TestTargetNew(
2263             level = TestLevel.PARTIAL_COMPLETE,
2264             notes = "Verifies the functionality of compile(java.lang.String) & matcher(java.lang.CharSequence) methods.",
2265             method = "compile",
2266             args = {java.lang.String.class}
2267         ),
2268         @TestTargetNew(
2269             level = TestLevel.PARTIAL_COMPLETE,
2270             notes = "Verifies the functionality of compile(java.lang.String) & matcher(java.lang.CharSequence) methods.",
2271             method = "matcher",
2272             args = {java.lang.CharSequence.class}
2273         )
2274     })
2275     public void testQuantifiersWithSurrogatesSupplementary() {
2276         String patString = "\uD9A0\uDE81*abc";
2277         String testString = "\uD9A0\uDE81\uD9A0\uDE81abc";
2278         Pattern pat = Pattern.compile(patString);
2279         Matcher mat = pat.matcher(testString);
2280         assertTrue(mat.matches());
2281
2282         testString = "abc";
2283         mat = pat.matcher(testString);
2284         assertTrue(mat.matches());
2285     }
2286
2287     @TestTargets({
2288         @TestTargetNew(
2289             level = TestLevel.PARTIAL_COMPLETE,
2290             notes = "Verifies the functionality of compile(java.lang.String) & matcher(java.lang.CharSequence) methods.",
2291             method = "compile",
2292             args = {java.lang.String.class}
2293         ),
2294         @TestTargetNew(
2295             level = TestLevel.PARTIAL_COMPLETE,
2296             notes = "Verifies the functionality of compile(java.lang.String) & matcher(java.lang.CharSequence) methods.",
2297             method = "matcher",
2298             args = {java.lang.CharSequence.class}
2299         )
2300     })
2301     public void testAlternationsWithSurrogatesSupplementary() {
2302         String patString = "\uDE81|\uD9A0\uDE81|\uD9A0";
2303         String testString = "\uD9A0";
2304         Pattern pat = Pattern.compile(patString);
2305         Matcher mat = pat.matcher(testString);
2306         assertTrue(mat.matches());
2307
2308         testString = "\uDE81";
2309         mat = pat.matcher(testString);
2310         assertTrue(mat.matches());
2311
2312         testString = "\uD9A0\uDE81";
2313         mat = pat.matcher(testString);
2314         assertTrue(mat.matches());
2315
2316         testString = "\uDE81\uD9A0";
2317         mat = pat.matcher(testString);
2318         assertFalse(mat.matches());
2319     }
2320
2321     @TestTargets({
2322         @TestTargetNew(
2323             level = TestLevel.PARTIAL_COMPLETE,
2324             notes = "Verifies the functionality of compile(java.lang.String) & compile(java.lang.String, int) & matcher(java.lang.CharSequence) methods.",
2325             method = "compile",
2326             args = {java.lang.String.class}
2327         ),
2328         @TestTargetNew(
2329             level = TestLevel.PARTIAL_COMPLETE,
2330             notes = "Verifies the functionality of compile(java.lang.String) & compile(java.lang.String, int) & matcher(java.lang.CharSequence) methods.",
2331             method = "compile",
2332             args = {java.lang.String.class, int.class}
2333         ),
2334         @TestTargetNew(
2335             level = TestLevel.PARTIAL_COMPLETE,
2336             notes = "Verifies the functionality of compile(java.lang.String) & compile(java.lang.String, int) & matcher(java.lang.CharSequence) methods.",
2337             method = "matcher",
2338             args = {java.lang.CharSequence.class}
2339         )
2340     })
2341     public void testGroupsWithSurrogatesSupplementary() {
2342
2343         //this pattern matches nothing
2344         String patString = "(\uD9A0)\uDE81";
2345         String testString = "\uD9A0\uDE81";
2346         Pattern pat = Pattern.compile(patString);
2347         Matcher mat = pat.matcher(testString);
2348         assertFalse(mat.matches());
2349
2350         patString = "(\uD9A0)";
2351         testString = "\uD9A0\uDE81";
2352         pat = Pattern.compile(patString, Pattern.DOTALL);
2353         mat = pat.matcher(testString);
2354         assertFalse(mat.find());
2355     }
2356
2357     /*
2358      * Regression test for HARMONY-688
2359      */
2360     @TestTargets({
2361         @TestTargetNew(
2362             level = TestLevel.PARTIAL_COMPLETE,
2363             notes = "The test verifies the functionality of compile(java.lang.String) & matcher(java.lang.CharSequence) methods.",
2364             method = "compile",
2365             args = {java.lang.String.class}
2366         ),
2367         @TestTargetNew(
2368             level = TestLevel.PARTIAL_COMPLETE,
2369             notes = "The test verifies the functionality of compile(java.lang.String) & matcher(java.lang.CharSequence) methods.",
2370             method = "matcher",
2371             args = {java.lang.CharSequence.class}
2372         )
2373     })
2374     public void testUnicodeCategoryWithSurrogatesSupplementary() {
2375         Pattern p = Pattern.compile("\\p{javaLowerCase}");
2376         Matcher matcher = p.matcher("\uD801\uDC28");
2377         assertTrue(matcher.find());
2378     }
2379
2380     @TestTargetNew(
2381         level = TestLevel.PARTIAL_COMPLETE,
2382         notes = "The test doesn't verify Matcher and should be moved to PatterTest.",
2383         method = "split",
2384         args = {java.lang.CharSequence.class, int.class}
2385     )
2386     public void testSplitEmpty() {
2387
2388         Pattern pat = Pattern.compile("");
2389         String[] s = pat.split("", -1);
2390
2391         assertEquals(1, s.length);
2392         assertEquals("", s[0]);
2393     }
2394
2395     @TestTargetNew(
2396         level = TestLevel.COMPLETE,
2397         notes = "",
2398         method = "toString",
2399         args = {}
2400     )
2401     public void testToString() {
2402         for (int i = 0; i < testPatterns.length; i++) {
2403             Pattern p = Pattern.compile(testPatterns[i]);
2404             assertEquals(testPatterns[i], p.toString());
2405         }
2406     }
2407
2408 }