1 package org.codehaus.plexus.util;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import java.io.File;
20
21 import org.junit.jupiter.api.Test;
22
23 import static org.junit.jupiter.api.Assertions.assertFalse;
24 import static org.junit.jupiter.api.Assertions.assertTrue;
25
26
27
28
29
30
31
32 public class SelectorUtilsTest {
33
34
35
36 @Test
37 public void testMatchPath_DefaultFileSeparator() {
38 String separator = File.separator;
39
40
41 assertTrue(
42 SelectorUtils.matchPath(separator + "*" + separator + "a.txt", separator + "b" + separator + "a.txt"));
43
44 assertFalse(SelectorUtils.matchPath(separator + "*" + separator + "a.txt", "b" + separator + "a.txt"));
45
46 assertFalse(SelectorUtils.matchPath("*" + separator + "a.txt", separator + "b" + separator + "a.txt"));
47
48 assertTrue(SelectorUtils.matchPath("*" + separator + "a.txt", "b" + separator + "a.txt"));
49 }
50
51
52
53
54 @Test
55 public void testMatchPath_UnixFileSeparator() {
56 String separator = "/";
57
58
59 assertTrue(SelectorUtils.matchPath(
60 separator + "*" + separator + "a.txt", separator + "b" + separator + "a.txt", separator, false));
61
62 assertFalse(SelectorUtils.matchPath(
63 separator + "*" + separator + "a.txt", "b" + separator + "a.txt", separator, false));
64
65 assertFalse(SelectorUtils.matchPath(
66 "*" + separator + "a.txt", separator + "b" + separator + "a.txt", separator, false));
67
68 assertTrue(SelectorUtils.matchPath("*" + separator + "a.txt", "b" + separator + "a.txt", separator, false));
69 }
70
71
72
73
74 @Test
75 public void testMatchPath_WindowsFileSeparator() {
76 String separator = "\\";
77
78
79 assertTrue(SelectorUtils.matchPath(
80 separator + "*" + separator + "a.txt", separator + "b" + separator + "a.txt", separator, false));
81
82 assertFalse(SelectorUtils.matchPath(
83 separator + "*" + separator + "a.txt", "b" + separator + "a.txt", separator, false));
84
85 assertFalse(SelectorUtils.matchPath(
86 "*" + separator + "a.txt", separator + "b" + separator + "a.txt", separator, false));
87
88 assertTrue(SelectorUtils.matchPath("*" + separator + "a.txt", "b" + separator + "a.txt", separator, false));
89 }
90
91 @org.junit.jupiter.api.Test
92 public void testPatternMatchSingleWildcardPosix() {
93 assertFalse(SelectorUtils.matchPath("/com/test/*", "/com/test/test/hallo"));
94 }
95
96 @Test
97 public void testPatternMatchDoubleWildcardCaseInsensitivePosix() {
98 assertTrue(SelectorUtils.matchPath("/com/test/**", "/com/test/test/hallo"));
99 }
100
101 @Test
102 public void testPatternMatchDoubleWildcardPosix() {
103 assertTrue(SelectorUtils.matchPath("/com/test/**", "/com/test/test/hallo"));
104 }
105
106 @org.junit.jupiter.api.Test
107 public void testPatternMatchSingleWildcardWindows() {
108 assertFalse(SelectorUtils.matchPath("D:\\com\\test\\*", "D:\\com\\test\\test\\hallo"));
109
110 assertFalse(SelectorUtils.matchPath("D:/com/test/*", "D:/com/test/test/hallo"));
111 }
112
113 @Test
114 public void testPatternMatchDoubleWildcardWindows() {
115 assertTrue(SelectorUtils.matchPath("D:\\com\\test\\**", "D:\\com\\test\\test\\hallo"));
116
117 assertTrue(SelectorUtils.matchPath("D:\\com\\test\\**", "D:/com/test/test/hallo"));
118 }
119 }