1 // Tags: JDK1.4 |
|
2 |
|
3 // Copyright (C) 2005 Mark J. Wielaard (mark@klomp.org) |
|
4 |
|
5 // This file is part of Mauve. |
|
6 |
|
7 // Mauve is free software; you can redistribute it and/or modify |
|
8 // it under the terms of the GNU General Public License as published by |
|
9 // the Free Software Foundation; either version 2, or (at your option) |
|
10 // any later version. |
|
11 |
|
12 // Mauve is distributed in the hope that it will be useful, |
|
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15 // GNU General Public License for more details. |
|
16 |
|
17 // You should have received a copy of the GNU General Public License |
|
18 // along with Mauve; see the file COPYING. If not, write to |
|
19 // the Free Software Foundation, 59 Temple Place - Suite 330, |
|
20 // Boston, MA 02111-1307, USA. |
|
21 |
|
22 package gnu.testlet.java.util.regex.Pattern; |
|
23 |
|
24 import gnu.testlet.*; |
|
25 import java.util.regex.*; |
|
26 |
|
27 public class matches implements Testlet |
|
28 { |
|
29 private TestHarness harness; |
|
30 |
|
31 /** |
|
32 * Tests whether things match completely (not just partially) as |
|
33 * suggested by Timo Juhani Lindfors (timo.lindfors@iki.fi). |
|
34 */ |
|
35 public void test (TestHarness harness) |
|
36 { |
|
37 try |
|
38 { |
|
39 harness.check(!Pattern.matches("b", "ab")); |
|
40 harness.check(Pattern.matches("ab", "ab")); |
|
41 harness.check(!Pattern.matches("abab", "abababab")); |
|
42 harness.check(Pattern.matches("abababab", "abababab")); |
|
43 |
|
44 harness.check(!Pattern.matches("(\\w,)+", "a,b,c,d,e")); |
|
45 harness.check(Pattern.matches("(\\w,)+", "a,b,c,d,e,")); |
|
46 |
|
47 harness.check(!Pattern.matches("\\d+", "123,456")); |
|
48 harness.check(Pattern.matches("\\d+,\\d+", "123,456")); |
|
49 harness.check(!Pattern.matches("\\d+,\\d+", "123,456,789")); |
|
50 harness.check(Pattern.matches("\\d+,\\d+,\\d+", "123,456,789")); |
|
51 harness.check(!Pattern.matches("\\d+,\\d+,\\d+,", "123,456,789")); |
|
52 harness.check(Pattern.matches("\\d+,\\d+,\\d+,", "123,456,789,")); |
|
53 |
|
54 harness.check(!Pattern.matches("[a-c]", "abc")); |
|
55 harness.check(!Pattern.matches("[a-c][a-c]", "abc")); |
|
56 harness.check(Pattern.matches("[a-c][a-c][a-c]", "abc")); |
|
57 harness.check(!Pattern.matches("[a-c][a-c][a-c][a-c]", "abc")); |
|
58 |
|
59 harness.check(!Pattern.matches("[a-z]*", "abc1defZghi")); |
|
60 harness.check(!Pattern.matches("([a-z]|\\d)*", "abc1defZghi")); |
|
61 harness.check(Pattern.matches("([a-z]|\\d|[A-Z])*", "abc1defZghi")); |
|
62 harness.check(!Pattern.matches("([a-z]|\\d|[A-Z])*", ",abc1defZghi")); |
|
63 harness.check(!Pattern.matches("([a-z]|\\d|[A-Z])*", "abc1defZghi,")); |
|
64 harness.check(!Pattern.matches("([a-z]|\\d|[A-Z])*", ",abc1defZghi,")); |
|
65 |
|
66 harness.check(Pattern.matches("()*", "")); |
|
67 harness.check(!Pattern.matches("()*", "x")); |
|
68 harness.check(Pattern.matches("(b*c*)*", "")); |
|
69 harness.check(Pattern.matches("(b*c*)*", "cbbcbbb")); |
|
70 harness.check(Pattern.matches("(b*c*)+", "")); |
|
71 harness.check(Pattern.matches("(b*c*)+", "cbbcbbb")); |
|
72 harness.check(Pattern.matches("(b*c*){3,}", "cbbcbbb")); |
|
73 harness.check(Pattern.matches("(b*c*){10,}", "cbbcbbb")); |
|
74 } |
|
75 catch(PatternSyntaxException pse) |
|
76 { |
|
77 harness.debug(pse); |
|
78 harness.check(false, pse.toString()); |
|
79 } |
|
80 } |
|
81 } |
|