01: // Copyright 2006 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // Unless required by applicable law or agreed to in writing, software
10: // distributed under the License is distributed on an "AS IS" BASIS,
11: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: // See the License for the specific language governing permissions and
13: // limitations under the License.
14:
15: package org.apache.tapestry.internal.test;
16:
17: import static org.easymock.EasyMock.reportMatcher;
18:
19: import org.easymock.IArgumentMatcher;
20:
21: /**
22: * Special version of string equality used to compare two snippets of code. This is somewhat
23: * simpleminded (it certainly doesn't understand about literal strings in quotes). It works by
24: * eliminating unecessary whitespace around curly braces, then reducing all whitespace to a single
25: * space.
26: *
27: *
28: */
29: public class CodeEq implements IArgumentMatcher {
30: private final String _code;
31:
32: public CodeEq(String input) {
33: _code = strip(input);
34: }
35:
36: public boolean matches(Object argument) {
37: String string = (String) argument;
38: String stripped = strip(string);
39:
40: return _code.equals(stripped);
41: }
42:
43: public void appendTo(StringBuffer buffer) {
44: buffer.append("codeEq(");
45: buffer.append(_code);
46: buffer.append(")");
47: }
48:
49: public static String codeEq(String input) {
50: reportMatcher(new CodeEq(input));
51:
52: return null;
53: }
54:
55: static String strip(String input) {
56: return input.trim().replaceAll("\\s*\\{\\s*", "{").replaceAll(
57: "\\s*\\}\\s*", "}").replaceAll("\\s+", " ");
58: }
59: }
|