View Javadoc
1   package org.codehaus.plexus.util;
2   
3   /*
4    * Copyright The Codehaus Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import org.junit.jupiter.api.Test;
20  
21  import static org.junit.jupiter.api.Assertions.assertArrayEquals;
22  import static org.junit.jupiter.api.Assertions.assertEquals;
23  import static org.junit.jupiter.api.Assertions.assertFalse;
24  import static org.junit.jupiter.api.Assertions.assertTrue;
25  
26  /**
27   * <p>MatchPatternTest class.</p>
28   *
29   * @author Kristian Rosenvold
30   * @since 3.4.0
31   */
32  class MatchPatternTest {
33  
34      @Test
35      void getSource() {
36          MatchPattern mp = MatchPattern.fromString("ABC*");
37          assertEquals("ABC*", mp.getSource());
38          mp = MatchPattern.fromString("%ant[some/ABC*]");
39          assertEquals("some/ABC*", mp.getSource());
40          mp = MatchPattern.fromString("%regex[[ABC].*]");
41          assertEquals("[ABC].*", mp.getSource());
42      }
43  
44      @Test
45      void matchPath() {
46          MatchPattern mp = MatchPattern.fromString("ABC*");
47          assertTrue(mp.matchPath("ABCD", true));
48      }
49  
50      /**
51       * @see <a href="https://github.com/codehaus-plexus/plexus-utils/issues/63">Issue #63</a>
52       */
53      @Test
54      void matchPatternStart() {
55          MatchPattern mp = MatchPattern.fromString("ABC*");
56  
57          assertTrue(mp.matchPatternStart("ABCD", true));
58          assertFalse(mp.matchPatternStart("AbCD", true));
59  
60          assertTrue(mp.matchPatternStart("ABCD", false));
61          assertTrue(mp.matchPatternStart("AbCD", false));
62  
63          assertFalse(mp.matchPatternStart("XXXX", true));
64          assertFalse(mp.matchPatternStart("XXXX", false));
65      }
66  
67      @Test
68      void tokenizePathToString() {
69          String[] expected = {"hello", "world"};
70          String[] actual = MatchPattern.tokenizePathToString("hello/world", "/");
71          assertArrayEquals(expected, actual);
72  
73          actual = MatchPattern.tokenizePathToString("/hello/world", "/");
74          assertArrayEquals(expected, actual);
75  
76          actual = MatchPattern.tokenizePathToString("/hello/world/", "/");
77          assertArrayEquals(expected, actual);
78      }
79  }