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.ioc.internal;
16:
17: import static org.testng.Assert.assertFalse;
18: import static org.testng.Assert.assertTrue;
19:
20: import org.testng.annotations.Test;
21:
22: /**
23: *
24: */
25: public class GlobPatternMatcherTest {
26: private boolean globMatch(String input, String pattern) {
27: return new GlobPatternMatcher(pattern).matches(input);
28: }
29:
30: @Test
31: public void glob_match_exact() {
32: assertTrue(globMatch("fred", "fred"));
33: assertTrue(globMatch("fred", "FRED"));
34: assertFalse(globMatch("xfred", "fred"));
35: assertFalse(globMatch("fredx", "fred"));
36: assertFalse(globMatch("fred", "xfred"));
37: assertFalse(globMatch("fred", "fredx"));
38: }
39:
40: @Test
41: public void glob_match_wild() {
42: assertTrue(globMatch("fred", "*"));
43: assertTrue(globMatch("", "*"));
44: }
45:
46: @Test
47: public void glob_match_prefix() {
48: assertTrue(globMatch("fred.Barney", "*Barney"));
49: assertTrue(globMatch("fred.Barney", "*BARNEY"));
50: assertFalse(globMatch("fred.Barneyx", "*Barney"));
51: assertFalse(globMatch("fred.Barney", "*Barneyx"));
52: assertFalse(globMatch("fred.Barney", "*xBarney"));
53: }
54:
55: @Test
56: public void glob_match_suffix() {
57: assertTrue(globMatch("fred.Barney", "fred*"));
58: assertTrue(globMatch("fred.Barney", "FRED*"));
59: assertFalse(globMatch("xfred.Barney", "fred*"));
60: assertFalse(globMatch("fred.Barney", "fredx*"));
61: assertFalse(globMatch("fred.Barney", "xfred*"));
62: }
63:
64: @Test
65: public void glob_match_infix() {
66: assertTrue(globMatch("fred.Barney", "*d.B*"));
67: assertTrue(globMatch("fred.Barney", "*D.B*"));
68: assertTrue(globMatch("fred.Barney", "*Barney*"));
69: assertTrue(globMatch("fred.Barney", "*fred*"));
70: assertTrue(globMatch("fred.Barney", "*FRED*"));
71: assertFalse(globMatch("fred.Barney", "*flint*"));
72: }
73:
74: }
|