OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 import 'package:glob/glob.dart'; |
| 6 import 'package:unittest/unittest.dart'; |
| 7 |
| 8 void main() { |
| 9 test("supports backslash-escaped characters", () { |
| 10 expect(r"\*[]{,}?()", contains(new Glob(r"\\\*\[\]\{\,\}\?\(\)"))); |
| 11 }); |
| 12 |
| 13 test("disallows an empty glob", () { |
| 14 expect(() => new Glob(""), throwsFormatException); |
| 15 }); |
| 16 |
| 17 group("range", () { |
| 18 test("supports either ^ or ! for negated ranges", () { |
| 19 var bang = new Glob("fo[!a-z]"); |
| 20 expect("foo", isNot(contains(bang))); |
| 21 expect("fo2", contains(bang)); |
| 22 |
| 23 var caret = new Glob("fo[^a-z]"); |
| 24 expect("foo", isNot(contains(bang))); |
| 25 expect("fo2", contains(bang)); |
| 26 }); |
| 27 |
| 28 test("supports backslash-escaped characters", () { |
| 29 var glob = new Glob(r"fo[\*\--\]]"); |
| 30 expect("fo]", contains(glob)); |
| 31 expect("fo-", contains(glob)); |
| 32 expect("fo*", contains(glob)); |
| 33 }); |
| 34 |
| 35 test("disallows inverted ranges", () { |
| 36 expect(() => new Glob(r"[z-a]"), throwsFormatException); |
| 37 }); |
| 38 |
| 39 test("disallows empty ranges", () { |
| 40 expect(() => new Glob(r"[]"), throwsFormatException); |
| 41 }); |
| 42 |
| 43 test("disallows unclosed ranges", () { |
| 44 expect(() => new Glob(r"[abc"), throwsFormatException); |
| 45 expect(() => new Glob(r"[-"), throwsFormatException); |
| 46 }); |
| 47 |
| 48 test("disallows dangling ]", () { |
| 49 expect(() => new Glob(r"abc]"), throwsFormatException); |
| 50 }); |
| 51 |
| 52 test("disallows explicit /", () { |
| 53 expect(() => new Glob(r"[/]"), throwsFormatException); |
| 54 expect(() => new Glob(r"[ -/]"), throwsFormatException); |
| 55 expect(() => new Glob(r"[/-~]"), throwsFormatException); |
| 56 }); |
| 57 }); |
| 58 |
| 59 group("options", () { |
| 60 test("allows empty branches", () { |
| 61 var glob = new Glob("foo{,bar}"); |
| 62 expect("foo", contains(glob)); |
| 63 expect("foobar", contains(glob)); |
| 64 }); |
| 65 |
| 66 test("disallows empty options", () { |
| 67 expect(() => new Glob("{}"), throwsFormatException); |
| 68 }); |
| 69 |
| 70 test("disallows single options", () { |
| 71 expect(() => new Glob("{foo}"), throwsFormatException); |
| 72 }); |
| 73 |
| 74 test("disallows unclosed options", () { |
| 75 expect(() => new Glob("{foo,bar"), throwsFormatException); |
| 76 expect(() => new Glob("{foo,"), throwsFormatException); |
| 77 }); |
| 78 |
| 79 test("disallows dangling }", () { |
| 80 expect(() => new Glob("foo}"), throwsFormatException); |
| 81 }); |
| 82 |
| 83 test("disallows dangling ] in options", () { |
| 84 expect(() => new Glob(r"{abc]}"), throwsFormatException); |
| 85 }); |
| 86 }); |
| 87 |
| 88 test("disallows unescaped parens", () { |
| 89 expect(() => new Glob("foo(bar"), throwsFormatException); |
| 90 expect(() => new Glob("foo)bar"), throwsFormatException); |
| 91 }); |
| 92 } |
OLD | NEW |