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 |
| 53 group("options", () { |
| 54 test("allows empty branches", () { |
| 55 var glob = new Glob("foo{,bar}"); |
| 56 expect("foo", contains(glob)); |
| 57 expect("foobar", contains(glob)); |
| 58 }); |
| 59 |
| 60 test("disallows empty options", () { |
| 61 expect(() => new Glob("{}"), throwsFormatException); |
| 62 }); |
| 63 |
| 64 test("disallows single options", () { |
| 65 expect(() => new Glob("{foo}"), throwsFormatException); |
| 66 }); |
| 67 |
| 68 test("disallows unclosed options", () { |
| 69 expect(() => new Glob("{foo,bar"), throwsFormatException); |
| 70 expect(() => new Glob("{foo,"), throwsFormatException); |
| 71 }); |
| 72 |
| 73 test("disallows dangling }", () { |
| 74 expect(() => new Glob("foo}"), throwsFormatException); |
| 75 }); |
| 76 |
| 77 test("disallows dangling ] in options", () { |
| 78 expect(() => new Glob(r"{abc]}"), throwsFormatException); |
| 79 }); |
| 80 }); |
| 81 |
| 82 test("disallows unescaped parens", () { |
| 83 expect(() => new Glob("foo(bar"), throwsFormatException); |
| 84 expect(() => new Glob("foo)bar"), throwsFormatException); |
| 85 }); |
| 86 } |
OLD | NEW |