01: package test.org.mandarax.util;
02:
03: /*
04: * Copyright (C) 1999-2004 <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</a>
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2 of the License, or (at your option) any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public
17: * License along with this library; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19: */
20:
21: import java.util.regex.*;
22:
23: import org.mandarax.util.regex.WildcardMatcher;
24:
25: import junit.framework.TestCase;
26:
27: /**
28: * Test case for the wildcard matcher. Uses the DB instance.
29: * @author <A href="http://www-ist.massey.ac.nz/JBDietrich" target="_top">Jens Dietrich</A>
30: * @version 3.4 <7 March 05>
31: * @since 3.0
32: */
33:
34: public class WildcardMatcherTest extends TestCase {
35: private String pattern = null;
36: private String text = null;
37: private boolean shouldMatch = true;
38:
39: /**
40: * Constructor.
41: * @param pattern the pattern containing wildcards
42: * @param text the text
43: * @param shouldMatch whether pattern matching should succeed
44: */
45: public WildcardMatcherTest(String pattern, String text,
46: boolean shouldMatch) {
47: super ("test");
48: this .pattern = pattern;
49: this .text = text;
50: this .shouldMatch = shouldMatch;
51: }
52:
53: /**
54: * Run the test case.
55: */
56: public void test() throws Exception {
57: Pattern p = WildcardMatcher.DB_INSTANCE.getPattern(pattern);
58: Matcher m = p.matcher(text);
59: assertTrue(shouldMatch == m.matches());
60: }
61:
62: /**
63: * Convert this object to a string.
64: * @return a string
65: */
66: public String toString() {
67: return "match whether " + text + " is like " + pattern
68: + (shouldMatch ? "" : " (should fail)");
69: }
70:
71: }
|