Chromium Code Reviews| Index: pkg/glob/test/parse_test.dart |
| diff --git a/pkg/glob/test/parse_test.dart b/pkg/glob/test/parse_test.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6395ffc8b5f4305de8fcad8426f4c885862fc323 |
| --- /dev/null |
| +++ b/pkg/glob/test/parse_test.dart |
| @@ -0,0 +1,84 @@ |
| +// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +import 'package:glob/glob.dart'; |
| +import 'package:unittest/unittest.dart'; |
| + |
| +void main() { |
| + test("supports backslash-escaped characters", () { |
| + expect(r"\*[]{,}?()", contains(new Glob(r"\\\*\[\]\{\,\}\?\(\)"))); |
| + }); |
| + |
| + test("disallows an empty glob", () { |
| + expect(() => new Glob(""), throwsFormatException); |
| + }); |
| + |
| + group("range", () { |
| + test("supports either ^ or ! for negated ranges", () { |
| + var bang = new Glob("fo[!a-z]"); |
| + expect("foo", isNot(contains(bang))); |
| + expect("fo1", contains(bang)); |
|
Bob Nystrom
2014/08/27 22:16:44
Use something other than 1 here.
nweiz
2014/09/02 19:48:16
Done.
|
| + |
| + var caret = new Glob("fo[^a-z]"); |
| + expect("foo", isNot(contains(bang))); |
| + expect("fo1", contains(bang)); |
| + }); |
| + |
| + test("supports backslash-escaped characters", () { |
| + var glob = new Glob(r"fo[\*\--\]]"); |
| + expect("fo]", contains(glob)); |
| + expect("fo-", contains(glob)); |
| + expect("fo*", contains(glob)); |
| + }); |
| + |
| + test("disallows inverted ranges", () { |
| + expect(() => new Glob(r"[z-a]"), throwsFormatException); |
| + }); |
| + |
| + test("disallows empty ranges", () { |
| + expect(() => new Glob(r"[]"), throwsFormatException); |
| + }); |
| + |
| + test("disallows unclosed ranges", () { |
| + expect(() => new Glob(r"[abc"), throwsFormatException); |
| + }); |
| + |
| + test("disallows dangling ]", () { |
| + expect(() => new Glob(r"abc]"), throwsFormatException); |
| + }); |
|
Bob Nystrom
2014/08/27 22:16:44
Test "[-]", "[a-]", "[-b]", and "[-".
nweiz
2014/09/02 19:48:16
I think the first three are actually expected to w
|
| + }); |
| + |
| + group("options", () { |
| + test("allows empty branches", () { |
| + var glob = new Glob("foo{,bar}"); |
| + expect("foo", contains(glob)); |
| + expect("foobar", contains(glob)); |
| + }); |
| + |
| + test("disallows empty options", () { |
| + expect(() => new Glob("{}"), throwsFormatException); |
| + }); |
| + |
| + test("disallows single options", () { |
| + expect(() => new Glob("{foo}"), throwsFormatException); |
| + }); |
| + |
| + test("disallows unclosed options", () { |
| + expect(() => new Glob("{foo,bar"), throwsFormatException); |
| + }); |
| + |
| + test("disallows dangling }", () { |
| + expect(() => new Glob("foo}"), throwsFormatException); |
| + }); |
| + |
| + test("disallows dangling ] in options", () { |
| + expect(() => new Glob(r"{abc]}"), throwsFormatException); |
| + }); |
|
Bob Nystrom
2014/08/27 22:16:45
Test "{abc,".
nweiz
2014/09/02 19:48:16
Done.
|
| + }); |
| + |
| + test("disallows unescaped parens", () { |
| + expect(() => new Glob("foo(bar"), throwsFormatException); |
| + expect(() => new Glob("foo)bar"), throwsFormatException); |
| + }); |
| +} |