01: // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
02: // Released under the terms of the GNU General Public License version 2 or later.
03: package fitnesse.testutil;
04:
05: import junit.framework.TestCase;
06: import java.util.regex.Matcher;
07: import java.util.regex.Pattern;
08:
09: public class RegexTest extends TestCase {
10: public static void assertMatches(String regexp, String string) {
11: assertHasRegexp(regexp, string);
12: }
13:
14: public static void assertNotMatches(String regexp, String string) {
15: assertDoesntHaveRegexp(regexp, string);
16: }
17:
18: public static void assertHasRegexp(String regexp, String output) {
19: Matcher match = Pattern.compile(regexp,
20: Pattern.MULTILINE | Pattern.DOTALL).matcher(output);
21: boolean found = match.find();
22: if (!found)
23: fail("The regexp <" + regexp + "> was not found in: "
24: + output + ".");
25: }
26:
27: public static void assertDoesntHaveRegexp(String regexp,
28: String output) {
29: Matcher match = Pattern.compile(regexp, Pattern.MULTILINE)
30: .matcher(output);
31: boolean found = match.find();
32: if (found)
33: fail("The regexp <" + regexp + "> was found.");
34: }
35:
36: public static void assertSubString(String substring, String string) {
37: if (string.indexOf(substring) == -1)
38: fail("substring '" + substring + "' not found.");
39: }
40:
41: public static void assertNotSubString(String subString,
42: String string) {
43: if (string.indexOf(subString) > -1)
44: fail("expecting substring:'" + subString + "' in string:'"
45: + string + "'");
46: }
47:
48: public static String divWithIdAndContent(String id,
49: String expectedDivContent) {
50: return "<div.*?id=\"" + id + "\".*?>" + expectedDivContent
51: + "</div>";
52: }
53: }
|