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:path/path.dart' as p; | 6 import 'package:path/path.dart' as p; |
7 import 'package:unittest/unittest.dart'; | 7 import 'package:unittest/unittest.dart'; |
8 | 8 |
9 const ASCII_WITHOUT_SLASH = "\t\n\r !\"#\$%&'()*+`-.0123456789:;<=>?@ABCDEFGHIJ" | 9 const RAW_ASCII_WITHOUT_SLASH = "\t\n\r !\"#\$%&'()*+`-.0123456789:;<=>?@ABCDEF" |
10 "KLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"; | 10 "GHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~"; |
| 11 |
| 12 // URL-encode the path for a URL context. |
| 13 final asciiWithoutSlash = p.style == p.Style.url ? |
| 14 Uri.encodeFull(RAW_ASCII_WITHOUT_SLASH) : RAW_ASCII_WITHOUT_SLASH; |
11 | 15 |
12 void main() { | 16 void main() { |
13 test("literals match exactly", () { | 17 test("literals match exactly", () { |
14 expect("foo", contains(new Glob("foo"))); | 18 expect("foo", contains(new Glob("foo"))); |
15 expect("foo/bar", contains(new Glob("foo/bar"))); | 19 expect("foo/bar", contains(new Glob("foo/bar"))); |
16 expect("foo*", contains(new Glob(r"foo\*"))); | 20 expect("foo*", contains(new Glob(r"foo\*"))); |
17 }); | 21 }); |
18 | 22 |
| 23 test("backslashes match nothing on Windows", () { |
| 24 expect(r"foo\bar", |
| 25 isNot(contains(new Glob(r"foo\\bar", context: p.windows)))); |
| 26 }); |
| 27 |
19 group("star", () { | 28 group("star", () { |
20 test("matches non-separator characters", () { | 29 test("matches non-separator characters", () { |
21 var glob = new Glob("*"); | 30 var glob = new Glob("*"); |
22 expect(ASCII_WITHOUT_SLASH, contains(glob)); | 31 expect(asciiWithoutSlash, contains(glob)); |
23 }); | 32 }); |
24 | 33 |
25 test("matches the empty string", () { | 34 test("matches the empty string", () { |
26 expect("foo", contains(new Glob("foo*"))); | 35 expect("foo", contains(new Glob("foo*"))); |
27 expect("", contains(new Glob("*"))); | 36 expect("", contains(new Glob("*"))); |
28 }); | 37 }); |
29 | 38 |
30 test("doesn't match separators", () { | 39 test("doesn't match separators", () { |
31 var glob = new Glob("*"); | 40 var glob = new Glob("*"); |
32 expect("foo/bar", isNot(contains(glob))); | 41 expect("foo/bar", isNot(contains(glob))); |
33 }); | 42 }); |
34 }); | 43 }); |
35 | 44 |
36 group("double star", () { | 45 group("double star", () { |
37 test("matches non-separator characters", () { | 46 test("matches non-separator characters", () { |
38 var glob = new Glob("**"); | 47 var glob = new Glob("**"); |
39 expect(ASCII_WITHOUT_SLASH, contains(glob)); | 48 expect(asciiWithoutSlash, contains(glob)); |
40 }); | 49 }); |
41 | 50 |
42 test("matches the empty string", () { | 51 test("matches the empty string", () { |
43 var glob = new Glob("foo**"); | 52 var glob = new Glob("foo**"); |
44 expect("foo", contains(glob)); | 53 expect("foo", contains(glob)); |
45 }); | 54 }); |
46 | 55 |
47 test("matches any level of nesting", () { | 56 test("matches any level of nesting", () { |
48 var glob = new Glob("**"); | 57 var glob = new Glob("**"); |
49 expect("a", contains(glob)); | 58 expect("a", contains(glob)); |
50 expect("a/b/c/d/e/f", contains(glob)); | 59 expect("a/b/c/d/e/f", contains(glob)); |
51 }); | 60 }); |
52 | 61 |
53 test("doesn't match unresolved dot dots", () { | 62 test("doesn't match unresolved dot dots", () { |
54 expect("../foo/bar", isNot(contains(new Glob("**")))); | 63 expect("../foo/bar", isNot(contains(new Glob("**")))); |
55 }); | 64 }); |
56 | 65 |
57 test("matches entities containing dot dots", () { | 66 test("matches entities containing dot dots", () { |
58 expect("..foo/bar", contains(new Glob("**"))); | 67 expect("..foo/bar", contains(new Glob("**"))); |
59 expect("foo../bar", contains(new Glob("**"))); | 68 expect("foo../bar", contains(new Glob("**"))); |
60 expect("foo/..bar", contains(new Glob("**"))); | 69 expect("foo/..bar", contains(new Glob("**"))); |
61 expect("foo/bar..", contains(new Glob("**"))); | 70 expect("foo/bar..", contains(new Glob("**"))); |
62 }); | 71 }); |
63 }); | 72 }); |
64 | 73 |
65 group("any char", () { | 74 group("any char", () { |
66 test("matches any non-separator character", () { | 75 test("matches any non-separator character", () { |
67 var glob = new Glob("foo?"); | 76 var glob = new Glob("foo?"); |
68 for (var char in ASCII_WITHOUT_SLASH.split('')) { | 77 for (var char in RAW_ASCII_WITHOUT_SLASH.split('')) { |
| 78 if (p.style == p.Style.url) char = Uri.encodeFull(char); |
69 expect("foo$char", contains(glob)); | 79 expect("foo$char", contains(glob)); |
70 } | 80 } |
71 }); | 81 }); |
72 | 82 |
73 test("doesn't match a separator", () { | 83 test("doesn't match a separator", () { |
74 expect("foo/bar", isNot(contains(new Glob("foo?bar")))); | 84 expect("foo/bar", isNot(contains(new Glob("foo?bar")))); |
75 }); | 85 }); |
76 }); | 86 }); |
77 | 87 |
78 group("range", () { | 88 group("range", () { |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 expect(r"http://foo.com/bar", | 285 expect(r"http://foo.com/bar", |
276 contains(new Glob("http://**", context: p.url))); | 286 contains(new Glob("http://**", context: p.url))); |
277 expect(r"http://foo.com/bar", | 287 expect(r"http://foo.com/bar", |
278 contains(new Glob("http://foo.com/**", context: p.url))); | 288 contains(new Glob("http://foo.com/**", context: p.url))); |
279 | 289 |
280 expect("/foo/bar", contains(new Glob("/foo/bar", context: p.url))); | 290 expect("/foo/bar", contains(new Glob("/foo/bar", context: p.url))); |
281 expect("/foo/bar", isNot(contains(new Glob("**", context: p.url)))); | 291 expect("/foo/bar", isNot(contains(new Glob("**", context: p.url)))); |
282 expect("/foo/bar", contains(new Glob("/**", context: p.url))); | 292 expect("/foo/bar", contains(new Glob("/**", context: p.url))); |
283 }); | 293 }); |
284 } | 294 } |
OLD | NEW |