OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import 'package:glob/glob.dart'; | 5 import 'package:glob/glob.dart'; |
6 import 'package:glob/src/utils.dart'; | 6 import 'package:glob/src/utils.dart'; |
7 import 'package:path/path.dart' as p; | 7 import 'package:path/path.dart' as p; |
8 import 'package:test/test.dart'; | 8 import 'package:test/test.dart'; |
9 | 9 |
10 const RAW_ASCII_WITHOUT_SLASH = "\t\n\r !\"#\$%&'()*+`-.0123456789:;<=>?@ABCDEF" | 10 const RAW_ASCII_WITHOUT_SLASH = "\t\n\r !\"#\$%&'()*+`-.0123456789:;<=>?@ABCDEF" |
11 "GHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~"; | 11 "GHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~"; |
12 | 12 |
13 // URL-encode the path for a URL context. | 13 // URL-encode the path for a URL context. |
14 final asciiWithoutSlash = p.style == p.Style.url ? | 14 final asciiWithoutSlash = p.style == p.Style.url |
15 Uri.encodeFull(RAW_ASCII_WITHOUT_SLASH) : RAW_ASCII_WITHOUT_SLASH; | 15 ? Uri.encodeFull(RAW_ASCII_WITHOUT_SLASH) |
| 16 : RAW_ASCII_WITHOUT_SLASH; |
16 | 17 |
17 void main() { | 18 void main() { |
18 test("literals match exactly", () { | 19 test("literals match exactly", () { |
19 expect("foo", contains(new Glob("foo"))); | 20 expect("foo", contains(new Glob("foo"))); |
20 expect("foo/bar", contains(new Glob("foo/bar"))); | 21 expect("foo/bar", contains(new Glob("foo/bar"))); |
21 expect("foo*", contains(new Glob(r"foo\*"))); | 22 expect("foo*", contains(new Glob(r"foo\*"))); |
22 }); | 23 }); |
23 | 24 |
24 test("backslashes match nothing on Windows", () { | 25 test("backslashes match nothing on Windows", () { |
25 expect(r"foo\bar", | 26 expect( |
26 isNot(contains(new Glob(r"foo\\bar", context: p.windows)))); | 27 r"foo\bar", isNot(contains(new Glob(r"foo\\bar", context: p.windows)))); |
27 }); | 28 }); |
28 | 29 |
29 group("star", () { | 30 group("star", () { |
30 test("matches non-separator characters", () { | 31 test("matches non-separator characters", () { |
31 var glob = new Glob("*"); | 32 var glob = new Glob("*"); |
32 expect(asciiWithoutSlash, contains(glob)); | 33 expect(asciiWithoutSlash, contains(glob)); |
33 }); | 34 }); |
34 | 35 |
35 test("matches the empty string", () { | 36 test("matches the empty string", () { |
36 expect("foo", contains(new Glob("foo*"))); | 37 expect("foo", contains(new Glob("foo*"))); |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 }); | 231 }); |
231 | 232 |
232 test("an absolute path can be matched by a relative glob", () { | 233 test("an absolute path can be matched by a relative glob", () { |
233 var path = p.absolute('foo/bar'); | 234 var path = p.absolute('foo/bar'); |
234 expect(path, contains(new Glob("foo/bar"))); | 235 expect(path, contains(new Glob("foo/bar"))); |
235 }); | 236 }); |
236 | 237 |
237 test("a relative path can be matched by an absolute glob", () { | 238 test("a relative path can be matched by an absolute glob", () { |
238 var pattern = separatorToForwardSlash(p.absolute('foo/bar')); | 239 var pattern = separatorToForwardSlash(p.absolute('foo/bar')); |
239 expect('foo/bar', contains(new Glob(pattern))); | 240 expect('foo/bar', contains(new Glob(pattern))); |
240 }); | 241 }, testOn: 'vm'); |
241 | 242 |
242 group("with recursive: true", () { | 243 group("with recursive: true", () { |
243 var glob = new Glob("foo/bar", recursive: true); | 244 var glob = new Glob("foo/bar", recursive: true); |
244 | 245 |
245 test("still matches basic files", () { | 246 test("still matches basic files", () { |
246 expect("foo/bar", contains(glob)); | 247 expect("foo/bar", contains(glob)); |
247 }); | 248 }); |
248 | 249 |
249 test("matches subfiles", () { | 250 test("matches subfiles", () { |
250 expect("foo/bar/baz", contains(glob)); | 251 expect("foo/bar/baz", contains(glob)); |
(...skipping 12 matching lines...) Expand all Loading... |
263 expect("/foo/bar", contains(new Glob("/**", context: p.posix))); | 264 expect("/foo/bar", contains(new Glob("/**", context: p.posix))); |
264 }); | 265 }); |
265 | 266 |
266 test("absolute Windows paths", () { | 267 test("absolute Windows paths", () { |
267 expect(r"C:\foo\bar", contains(new Glob("C:/foo/bar", context: p.windows))); | 268 expect(r"C:\foo\bar", contains(new Glob("C:/foo/bar", context: p.windows))); |
268 expect(r"C:\foo\bar", isNot(contains(new Glob("**", context: p.windows)))); | 269 expect(r"C:\foo\bar", isNot(contains(new Glob("**", context: p.windows)))); |
269 expect(r"C:\foo\bar", contains(new Glob("C:/**", context: p.windows))); | 270 expect(r"C:\foo\bar", contains(new Glob("C:/**", context: p.windows))); |
270 | 271 |
271 expect(r"\\foo\bar\baz", | 272 expect(r"\\foo\bar\baz", |
272 contains(new Glob("//foo/bar/baz", context: p.windows))); | 273 contains(new Glob("//foo/bar/baz", context: p.windows))); |
273 expect(r"\\foo\bar\baz", | 274 expect( |
274 isNot(contains(new Glob("**", context: p.windows)))); | 275 r"\\foo\bar\baz", isNot(contains(new Glob("**", context: p.windows)))); |
275 expect(r"\\foo\bar\baz", contains(new Glob("//**", context: p.windows))); | 276 expect(r"\\foo\bar\baz", contains(new Glob("//**", context: p.windows))); |
276 expect(r"\\foo\bar\baz", | 277 expect( |
277 contains(new Glob("//foo/**", context: p.windows))); | 278 r"\\foo\bar\baz", contains(new Glob("//foo/**", context: p.windows))); |
278 }); | 279 }); |
279 | 280 |
280 test("absolute URL paths", () { | 281 test("absolute URL paths", () { |
281 expect(r"http://foo.com/bar", | 282 expect(r"http://foo.com/bar", |
282 contains(new Glob("http://foo.com/bar", context: p.url))); | 283 contains(new Glob("http://foo.com/bar", context: p.url))); |
283 expect(r"http://foo.com/bar", | 284 expect( |
284 isNot(contains(new Glob("**", context: p.url)))); | 285 r"http://foo.com/bar", isNot(contains(new Glob("**", context: p.url)))); |
285 expect(r"http://foo.com/bar", | 286 expect( |
286 contains(new Glob("http://**", context: p.url))); | 287 r"http://foo.com/bar", contains(new Glob("http://**", context: p.url))); |
287 expect(r"http://foo.com/bar", | 288 expect(r"http://foo.com/bar", |
288 contains(new Glob("http://foo.com/**", context: p.url))); | 289 contains(new Glob("http://foo.com/**", context: p.url))); |
289 | 290 |
290 expect("/foo/bar", contains(new Glob("/foo/bar", context: p.url))); | 291 expect("/foo/bar", contains(new Glob("/foo/bar", context: p.url))); |
291 expect("/foo/bar", isNot(contains(new Glob("**", context: p.url)))); | 292 expect("/foo/bar", isNot(contains(new Glob("**", context: p.url)))); |
292 expect("/foo/bar", contains(new Glob("/**", context: p.url))); | 293 expect("/foo/bar", contains(new Glob("/**", context: p.url))); |
293 }); | 294 }); |
294 | 295 |
295 group("when case-sensitive", () { | 296 group("when case-sensitive", () { |
296 test("literals match case-sensitively", () { | 297 test("literals match case-sensitively", () { |
297 expect("foo", contains(new Glob("foo", caseSensitive: true))); | 298 expect("foo", contains(new Glob("foo", caseSensitive: true))); |
298 expect("FOO", isNot(contains(new Glob("foo", caseSensitive: true)))); | 299 expect("FOO", isNot(contains(new Glob("foo", caseSensitive: true)))); |
299 expect("foo", isNot(contains(new Glob("FOO", caseSensitive: true)))); | 300 expect("foo", isNot(contains(new Glob("FOO", caseSensitive: true)))); |
300 }); | 301 }); |
301 | 302 |
302 test("ranges match case-sensitively", () { | 303 test("ranges match case-sensitively", () { |
303 expect("foo", contains(new Glob("[fx][a-z]o", caseSensitive: true))); | 304 expect("foo", contains(new Glob("[fx][a-z]o", caseSensitive: true))); |
304 expect("FOO", | 305 expect( |
305 isNot(contains(new Glob("[fx][a-z]o", caseSensitive: true)))); | 306 "FOO", isNot(contains(new Glob("[fx][a-z]o", caseSensitive: true)))); |
306 expect("foo", | 307 expect( |
307 isNot(contains(new Glob("[FX][A-Z]O", caseSensitive: true)))); | 308 "foo", isNot(contains(new Glob("[FX][A-Z]O", caseSensitive: true)))); |
308 }); | 309 }); |
309 | 310 |
310 test("sequences preserve case-sensitivity", () { | 311 test("sequences preserve case-sensitivity", () { |
311 expect("foo/bar", contains(new Glob("foo/bar", caseSensitive: true))); | 312 expect("foo/bar", contains(new Glob("foo/bar", caseSensitive: true))); |
312 expect("FOO/BAR", | 313 expect( |
313 isNot(contains(new Glob("foo/bar", caseSensitive: true)))); | 314 "FOO/BAR", isNot(contains(new Glob("foo/bar", caseSensitive: true)))); |
314 expect("foo/bar", | 315 expect( |
315 isNot(contains(new Glob("FOO/BAR", caseSensitive: true)))); | 316 "foo/bar", isNot(contains(new Glob("FOO/BAR", caseSensitive: true)))); |
316 }); | 317 }); |
317 | 318 |
318 test("options preserve case-sensitivity", () { | 319 test("options preserve case-sensitivity", () { |
319 expect("foo", contains(new Glob("{foo,bar}", caseSensitive: true))); | 320 expect("foo", contains(new Glob("{foo,bar}", caseSensitive: true))); |
320 expect("FOO", | 321 expect( |
321 isNot(contains(new Glob("{foo,bar}", caseSensitive: true)))); | 322 "FOO", isNot(contains(new Glob("{foo,bar}", caseSensitive: true)))); |
322 expect("foo", | 323 expect( |
323 isNot(contains(new Glob("{FOO,BAR}", caseSensitive: true)))); | 324 "foo", isNot(contains(new Glob("{FOO,BAR}", caseSensitive: true)))); |
324 }); | 325 }); |
325 }); | 326 }); |
326 | 327 |
327 group("when case-insensitive", () { | 328 group("when case-insensitive", () { |
328 test("literals match case-insensitively", () { | 329 test("literals match case-insensitively", () { |
329 expect("foo", contains(new Glob("foo", caseSensitive: false))); | 330 expect("foo", contains(new Glob("foo", caseSensitive: false))); |
330 expect("FOO", contains(new Glob("foo", caseSensitive: false))); | 331 expect("FOO", contains(new Glob("foo", caseSensitive: false))); |
331 expect("foo", contains(new Glob("FOO", caseSensitive: false))); | 332 expect("foo", contains(new Glob("FOO", caseSensitive: false))); |
332 }); | 333 }); |
333 | 334 |
334 test("ranges match case-insensitively", () { | 335 test("ranges match case-insensitively", () { |
335 expect("foo", contains(new Glob("[fx][a-z]o", caseSensitive: false))); | 336 expect("foo", contains(new Glob("[fx][a-z]o", caseSensitive: false))); |
336 expect("FOO", contains(new Glob("[fx][a-z]o", caseSensitive: false))); | 337 expect("FOO", contains(new Glob("[fx][a-z]o", caseSensitive: false))); |
337 expect("foo", contains(new Glob("[FX][A-Z]O", caseSensitive: false))); | 338 expect("foo", contains(new Glob("[FX][A-Z]O", caseSensitive: false))); |
338 }); | 339 }); |
339 | 340 |
340 test("sequences preserve case-insensitivity", () { | 341 test("sequences preserve case-insensitivity", () { |
341 expect("foo/bar", contains(new Glob("foo/bar", caseSensitive: false))); | 342 expect("foo/bar", contains(new Glob("foo/bar", caseSensitive: false))); |
342 expect("FOO/BAR", contains(new Glob("foo/bar", caseSensitive: false))); | 343 expect("FOO/BAR", contains(new Glob("foo/bar", caseSensitive: false))); |
343 expect("foo/bar", contains(new Glob("FOO/BAR", caseSensitive: false))); | 344 expect("foo/bar", contains(new Glob("FOO/BAR", caseSensitive: false))); |
344 }); | 345 }); |
345 | 346 |
346 test("options preserve case-insensitivity", () { | 347 test("options preserve case-insensitivity", () { |
347 expect("foo", contains(new Glob("{foo,bar}", caseSensitive: false))); | 348 expect("foo", contains(new Glob("{foo,bar}", caseSensitive: false))); |
348 expect("FOO", contains(new Glob("{foo,bar}", caseSensitive: false))); | 349 expect("FOO", contains(new Glob("{foo,bar}", caseSensitive: false))); |
349 expect("foo", contains(new Glob("{FOO,BAR}", caseSensitive: false))); | 350 expect("foo", contains(new Glob("{FOO,BAR}", caseSensitive: false))); |
350 }); | 351 }); |
351 }); | 352 }); |
352 } | 353 } |
OLD | NEW |