6
6
* http://www.eclipse.org/legal/epl-v10.html
7
7
*
8
8
* Contributors:
9
- * ralf - initial implementation and API
9
+ * Ralf Sternberg initial implementation and API
10
10
******************************************************************************/
11
11
package com .eclipsesource .jshint .ui .internal .preferences ;
12
12
@@ -32,12 +32,12 @@ public void emptyPattern_matchesAllFiles() {
32
32
}
33
33
34
34
@ Test
35
- public void emptyPattern_matchesAllPaths () {
35
+ public void emptyPattern_matchesOnlyRoot () {
36
36
PathPattern pattern = PathPattern .create ( "" );
37
37
38
38
assertTrue ( pattern .matchesFolder () );
39
- assertTrue ( pattern . matchesFolder ( "foo" ) );
40
- assertTrue ( pattern .matchesFolder ( "foo" , "bar " ) );
39
+
40
+ assertFalse ( pattern .matchesFolder ( "foo" ) );
41
41
}
42
42
43
43
@ Test
@@ -70,12 +70,21 @@ public void fileOnlyPattern_matchesFile() {
70
70
}
71
71
72
72
@ Test
73
- public void fileOnlyPattern_matchesAllPaths () {
73
+ public void fileOnlyPattern_matchesOnlyRoot () {
74
74
PathPattern pattern = PathPattern .create ( "*.js" );
75
75
76
- assertTrue ( pattern .matchesFolder ( "" ) );
77
- assertTrue ( pattern .matchesFolder ( "foo" ) );
78
- assertTrue ( pattern .matchesFolder ( "foo" , "bar" ) );
76
+ assertTrue ( pattern .matchesFolder () );
77
+
78
+ assertFalse ( pattern .matchesFolder ( "foo" ) );
79
+ }
80
+
81
+ @ Test
82
+ public void filePatternAtRootPath_matchesOnlyRoot () {
83
+ PathPattern pattern = PathPattern .create ( "/*.js" );
84
+
85
+ assertTrue ( pattern .matchesFolder () );
86
+
87
+ assertFalse ( pattern .matchesFolder ( "foo" ) );
79
88
}
80
89
81
90
@ Test
@@ -88,20 +97,19 @@ public void relativePathOnlyPattern_matchesAllFiles() {
88
97
}
89
98
90
99
@ Test
91
- public void relativePathOnlyPattern_matchesAnyPrefixPath () {
100
+ public void relativePathOnlyPattern_matchesExactPath () {
92
101
PathPattern pattern = PathPattern .create ( "foo/" );
93
102
94
103
assertTrue ( pattern .matchesFolder ( "foo" ) );
95
- assertTrue ( pattern .matchesFolder ( "doo" , "foo" ) );
96
- assertTrue ( pattern .matchesFolder ( "woo" , "doo" , "foo" ) );
97
104
98
- assertFalse ( pattern .matchesFolder ( "" ) );
105
+ assertFalse ( pattern .matchesFolder () );
99
106
assertFalse ( pattern .matchesFolder ( "bar" ) );
100
107
assertFalse ( pattern .matchesFolder ( "foo" , "bar" ) );
108
+ assertFalse ( pattern .matchesFolder ( "zoo" , "foo" ) );
101
109
}
102
110
103
111
@ Test
104
- public void absolutePathOnlyPattern_matchesAnyPrefixPath () {
112
+ public void absolutePathOnlyPattern_matchesExactPath () {
105
113
PathPattern pattern = PathPattern .create ( "/foo/" );
106
114
107
115
assertTrue ( pattern .matchesFolder ( "foo" ) );
@@ -113,14 +121,14 @@ public void absolutePathOnlyPattern_matchesAnyPrefixPath() {
113
121
}
114
122
115
123
@ Test
116
- public void nestedPathOnlyPattern_matchesPath () {
124
+ public void nestedPathOnlyPattern_matchesExactPath () {
117
125
PathPattern pattern = PathPattern .create ( "foo/bar/" );
118
126
119
127
assertTrue ( pattern .matchesFolder ( "foo" , "bar" ) );
120
- assertTrue ( pattern .matchesFolder ( "zoo" , "foo" , "bar" ) );
121
128
122
129
assertFalse ( pattern .matchesFolder ( "foo" ) );
123
130
assertFalse ( pattern .matchesFolder ( "bar" ) );
131
+ assertFalse ( pattern .matchesFolder ( "zoo" , "foo" , "bar" ) );
124
132
assertFalse ( pattern .matchesFolder ( "foo" , "bar" , "baz" ) );
125
133
}
126
134
@@ -161,6 +169,7 @@ public void wildcardSegment_isNotWildcardPath() {
161
169
assertTrue ( pattern .matchesFolder ( "foo-bar" ) );
162
170
163
171
assertFalse ( pattern .matchesFolder ( "foo" , "bar" ) );
172
+ assertFalse ( pattern .matchesFolder ( "foo" , "x" , "bar" ) );
164
173
}
165
174
166
175
@ Test
@@ -174,28 +183,19 @@ public void wildcardSegment_matchesExactlyOnePathSegment() {
174
183
}
175
184
176
185
@ Test
177
- public void filePatternAtRootPath () {
178
- PathPattern pattern = PathPattern .create ( "/*.foo" );
179
-
180
- assertTrue ( pattern .matchesFolder () );
181
-
182
- assertFalse ( pattern .matchesFolder ( "x" ) );
183
- assertFalse ( pattern .matchesFolder ( "foo" ) );
184
- }
185
-
186
- @ Test
187
- public void tooManySlashesInARow () {
188
- assertCreateFailsWithIAE ( "///foo" );
189
- assertCreateFailsWithIAE ( "foo///" );
190
- assertCreateFailsWithIAE ( "foo///bar" );
186
+ public void tooManySuccessiveSlashes () {
187
+ assertCreateFailsWithTooManySuccessiveSlashes ( "///foo" );
188
+ assertCreateFailsWithTooManySuccessiveSlashes ( "foo///" );
189
+ assertCreateFailsWithTooManySuccessiveSlashes ( "foo///bar" );
191
190
}
192
191
193
- private static void assertCreateFailsWithIAE ( String expression ) {
192
+ private static void assertCreateFailsWithTooManySuccessiveSlashes ( String expression ) {
194
193
try {
195
194
PathPattern .create ( expression );
196
195
fail ( "Expected IllegalArgumentsException for expression " + expression );
197
196
} catch ( IllegalArgumentException exception ) {
198
- assertTrue ( exception .getMessage ().contains ( "Too many slashes in a row" ) );
197
+ String expected = "Too many successive slashes in expression" ;
198
+ assertEquals ( expected , exception .getMessage () );
199
199
}
200
200
}
201
201
@@ -219,4 +219,61 @@ private static String split( String expression ) {
219
219
return Arrays .toString ( PathPattern .splitIntoSegmentPatterns ( expression ) );
220
220
}
221
221
222
+ @ Test
223
+ public void matchesAllFiles () {
224
+ assertTrue ( PathPattern .create ( "" ).matchesAllFiles () );
225
+ assertTrue ( PathPattern .create ( "/" ).matchesAllFiles () );
226
+ assertTrue ( PathPattern .create ( "//" ).matchesAllFiles () );
227
+ assertTrue ( PathPattern .create ( "src/" ).matchesAllFiles () );
228
+ assertTrue ( PathPattern .create ( "src//" ).matchesAllFiles () );
229
+ assertTrue ( PathPattern .create ( "*" ).matchesAllFiles () );
230
+ assertTrue ( PathPattern .create ( "/*" ).matchesAllFiles () );
231
+ assertTrue ( PathPattern .create ( "//*" ).matchesAllFiles () );
232
+ assertTrue ( PathPattern .create ( "src/*" ).matchesAllFiles () );
233
+ assertTrue ( PathPattern .create ( "src//*" ).matchesAllFiles () );
234
+
235
+ assertFalse ( PathPattern .create ( "*.*" ).matchesAllFiles () );
236
+ assertFalse ( PathPattern .create ( "*.js" ).matchesAllFiles () );
237
+ assertFalse ( PathPattern .create ( "src/*.js" ).matchesAllFiles () );
238
+ }
239
+
240
+ @ Test
241
+ public void matchesAllFolders () {
242
+ assertTrue ( PathPattern .create ( "//" ).matchesAllFolders () );
243
+ assertTrue ( PathPattern .create ( "//*.js" ).matchesAllFolders () );
244
+
245
+ assertFalse ( PathPattern .create ( "" ).matchesAllFolders () );
246
+ assertFalse ( PathPattern .create ( "/" ).matchesAllFolders () );
247
+ assertFalse ( PathPattern .create ( "src//" ).matchesAllFolders () );
248
+ assertFalse ( PathPattern .create ( "src//*.js" ).matchesAllFolders () );
249
+ assertFalse ( PathPattern .create ( "//src//" ).matchesAllFolders () );
250
+ assertFalse ( PathPattern .create ( "src//js/" ).matchesAllFolders () );
251
+ }
252
+
253
+ @ Test
254
+ public void getFilePattern () {
255
+ assertEquals ( "*" , PathPattern .create ( "" ).getFilePattern () );
256
+ assertEquals ( "*" , PathPattern .create ( "/" ).getFilePattern () );
257
+ assertEquals ( "*" , PathPattern .create ( "//" ).getFilePattern () );
258
+ assertEquals ( "*" , PathPattern .create ( "src/" ).getFilePattern () );
259
+ assertEquals ( "*" , PathPattern .create ( "src/*" ).getFilePattern () );
260
+ assertEquals ( "*.js" , PathPattern .create ( "src/*.js" ).getFilePattern () );
261
+ assertEquals ( "foo" , PathPattern .create ( "//foo" ).getFilePattern () );
262
+ }
263
+
264
+ @ Test
265
+ public void getPathPattern () {
266
+ assertEquals ( "" , PathPattern .create ( "" ).getPathPattern () );
267
+ assertEquals ( "" , PathPattern .create ( "file" ).getPathPattern () );
268
+ assertEquals ( "/" , PathPattern .create ( "/" ).getPathPattern () );
269
+ assertEquals ( "/" , PathPattern .create ( "/file" ).getPathPattern () );
270
+ assertEquals ( "//" , PathPattern .create ( "//" ).getPathPattern () );
271
+ assertEquals ( "//" , PathPattern .create ( "//file" ).getPathPattern () );
272
+ assertEquals ( "src/" , PathPattern .create ( "src/file" ).getPathPattern () );
273
+ assertEquals ( "src/" , PathPattern .create ( "src/*" ).getPathPattern () );
274
+ assertEquals ( "src//" , PathPattern .create ( "src//file" ).getPathPattern () );
275
+ assertEquals ( "src/js//" , PathPattern .create ( "src/js//file" ).getPathPattern () );
276
+ assertEquals ( "//src//js/" , PathPattern .create ( "//src//js/file" ).getPathPattern () );
277
+ }
278
+
222
279
}
0 commit comments