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 |
19 group("star", () { | 23 group("star", () { |
20 test("matches non-separator characters", () { | 24 test("matches non-separator characters", () { |
21 var glob = new Glob("*"); | 25 var glob = new Glob("*"); |
22 expect(ASCII_WITHOUT_SLASH, contains(glob)); | 26 expect(asciiWithoutSlash, contains(glob)); |
23 }); | 27 }); |
24 | 28 |
25 test("matches the empty string", () { | 29 test("matches the empty string", () { |
26 expect("foo", contains(new Glob("foo*"))); | 30 expect("foo", contains(new Glob("foo*"))); |
27 expect("", contains(new Glob("*"))); | 31 expect("", contains(new Glob("*"))); |
28 }); | 32 }); |
29 | 33 |
30 test("doesn't match separators", () { | 34 test("doesn't match separators", () { |
31 var glob = new Glob("*"); | 35 var glob = new Glob("*"); |
32 expect("foo/bar", isNot(contains(glob))); | 36 expect("foo/bar", isNot(contains(glob))); |
33 }); | 37 }); |
34 }); | 38 }); |
35 | 39 |
36 group("double star", () { | 40 group("double star", () { |
37 test("matches non-separator characters", () { | 41 test("matches non-separator characters", () { |
38 var glob = new Glob("**"); | 42 var glob = new Glob("**"); |
39 expect(ASCII_WITHOUT_SLASH, contains(glob)); | 43 expect(asciiWithoutSlash, contains(glob)); |
40 }); | 44 }); |
41 | 45 |
42 test("matches the empty string", () { | 46 test("matches the empty string", () { |
43 var glob = new Glob("foo**"); | 47 var glob = new Glob("foo**"); |
44 expect("foo", contains(glob)); | 48 expect("foo", contains(glob)); |
45 }); | 49 }); |
46 | 50 |
47 test("matches any level of nesting", () { | 51 test("matches any level of nesting", () { |
48 var glob = new Glob("**"); | 52 var glob = new Glob("**"); |
49 expect("a", contains(glob)); | 53 expect("a", contains(glob)); |
50 expect("a/b/c/d/e/f", contains(glob)); | 54 expect("a/b/c/d/e/f", contains(glob)); |
51 }); | 55 }); |
52 | 56 |
53 test("doesn't match unresolved dot dots", () { | 57 test("doesn't match unresolved dot dots", () { |
54 expect("../foo/bar", isNot(contains(new Glob("**")))); | 58 expect("../foo/bar", isNot(contains(new Glob("**")))); |
55 }); | 59 }); |
56 | 60 |
57 test("matches entities containing dot dots", () { | 61 test("matches entities containing dot dots", () { |
58 expect("..foo/bar", contains(new Glob("**"))); | 62 expect("..foo/bar", contains(new Glob("**"))); |
59 expect("foo../bar", contains(new Glob("**"))); | 63 expect("foo../bar", contains(new Glob("**"))); |
60 expect("foo/..bar", contains(new Glob("**"))); | 64 expect("foo/..bar", contains(new Glob("**"))); |
61 expect("foo/bar..", contains(new Glob("**"))); | 65 expect("foo/bar..", contains(new Glob("**"))); |
62 }); | 66 }); |
63 }); | 67 }); |
64 | 68 |
65 group("any char", () { | 69 group("any char", () { |
66 test("matches any non-separator character", () { | 70 test("matches any non-separator character", () { |
67 var glob = new Glob("foo?"); | 71 var glob = new Glob("foo?"); |
68 for (var char in ASCII_WITHOUT_SLASH.split('')) { | 72 for (var char in RAW_ASCII_WITHOUT_SLASH.split('')) { |
| 73 if (p.style == p.Style.url) char = Uri.encodeFull(char); |
69 expect("foo$char", contains(glob)); | 74 expect("foo$char", contains(glob)); |
70 } | 75 } |
71 }); | 76 }); |
72 | 77 |
73 test("doesn't match a separator", () { | 78 test("doesn't match a separator", () { |
74 expect("foo/bar", isNot(contains(new Glob("foo?bar")))); | 79 expect("foo/bar", isNot(contains(new Glob("foo?bar")))); |
75 }); | 80 }); |
76 }); | 81 }); |
77 | 82 |
78 group("range", () { | 83 group("range", () { |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 expect(r"http://foo.com/bar", | 280 expect(r"http://foo.com/bar", |
276 contains(new Glob("http://**", context: p.url))); | 281 contains(new Glob("http://**", context: p.url))); |
277 expect(r"http://foo.com/bar", | 282 expect(r"http://foo.com/bar", |
278 contains(new Glob("http://foo.com/**", context: p.url))); | 283 contains(new Glob("http://foo.com/**", context: p.url))); |
279 | 284 |
280 expect("/foo/bar", contains(new Glob("/foo/bar", context: p.url))); | 285 expect("/foo/bar", contains(new Glob("/foo/bar", context: p.url))); |
281 expect("/foo/bar", isNot(contains(new Glob("**", context: p.url)))); | 286 expect("/foo/bar", isNot(contains(new Glob("**", context: p.url)))); |
282 expect("/foo/bar", contains(new Glob("/**", context: p.url))); | 287 expect("/foo/bar", contains(new Glob("/**", context: p.url))); |
283 }); | 288 }); |
284 } | 289 } |
OLD | NEW |