01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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.ivy.plugins.matcher;
19:
20: import java.util.regex.PatternSyntaxException;
21:
22: /**
23: * @see GlobPatternMatcher
24: */
25: public class GlobPatternMatcherTest extends AbstractPatternMatcherTest {
26:
27: protected void setUp() throws Exception {
28: setUp(new GlobPatternMatcher(), false);
29: }
30:
31: public void testValidRegexpSyntaxAsNormalCharacter() {
32: Matcher matcher = patternMatcher.getMatcher(".");
33: assertFalse(matcher.matches(""));
34: assertTrue(matcher.matches("."));
35: assertFalse(matcher.matches("a"));
36: assertFalse(matcher.matches("aa"));
37: }
38:
39: public void testRegexpSyntaxAndGlob() {
40: Matcher matcher = patternMatcher.getMatcher(".*");
41: assertTrue(matcher.matches(".*"));
42: assertFalse(matcher.matches(""));
43: assertFalse(matcher.matches("a"));
44: assertTrue(matcher.matches(".a"));
45: assertFalse(matcher.matches("abcdef"));
46: assertTrue(matcher.matches(".abcdef"));
47: }
48:
49: public void testImplementation() {
50: }
51:
52: public void testQuoteMeta() {
53: Matcher matcher = patternMatcher.getMatcher("\\*");
54: assertTrue(matcher.matches("*"));
55: assertFalse(matcher.matches("X"));
56: assertFalse(matcher.matches("Xsfsdfsd"));
57: }
58:
59: public void testInvalidRegexpSyntaxAsNormalCharacter() {
60: Matcher matcher = patternMatcher.getMatcher("(");
61: assertTrue(matcher.matches("("));
62: }
63:
64: public void testGlob() {
65: Matcher matcher = patternMatcher.getMatcher("*ivy*");
66: assertTrue(matcher.matches("ivy"));
67: assertTrue(matcher.matches("abcdefivyuvw"));
68: assertTrue(matcher.matches("ivyuvw"));
69: assertTrue(matcher.matches("abcdefivy"));
70: }
71:
72: public void testInvalidSyntax() {
73: try {
74: patternMatcher.getMatcher("[");
75: fail("Should fail on invalid regexp syntax");
76: } catch (PatternSyntaxException e) {
77:
78: }
79: }
80: }
|