Chromium Code Reviews| Index: pkg/analyzer/test/src/util/glob_test.dart |
| diff --git a/pkg/analyzer/test/src/util/glob_test.dart b/pkg/analyzer/test/src/util/glob_test.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..731ecd371c5ac767a01a4f89fb24cfe97958dfa4 |
| --- /dev/null |
| +++ b/pkg/analyzer/test/src/util/glob_test.dart |
| @@ -0,0 +1,105 @@ |
| +// Copyright (c) 2015, 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. |
| + |
| +library test.analyzer.src.util.glob; |
| + |
| +import 'package:analyzer/src/util/glob.dart'; |
| +import 'package:unittest/unittest.dart'; |
| + |
| +import '../../reflective_tests.dart'; |
| +import '../../utils.dart'; |
| + |
| +main() { |
| + initializeTestEnvironment(); |
| + runReflectiveTests(GlobPosixTest); |
| + runReflectiveTests(GlobWindowsTest); |
| +} |
| + |
| +@reflectiveTest |
| +class GlobPosixTest { |
| + void test_question() { |
| + Glob glob = new Glob(r'/', r'?.dart'); |
| + expect(glob.matches(r'a.dart'), isTrue); |
| + expect(glob.matches(r'b.dart'), isTrue); |
| + expect(glob.matches(r'cc.dart'), isFalse); |
| + } |
| + |
| + void test_specialChars() { |
| + Glob glob = new Glob(r'/', r'*.dart'); |
| + expect(glob.matches(r'a.dart'), isTrue); |
| + expect(glob.matches('_-\a.dart'), isTrue); |
| + expect(glob.matches(r'^$*?.dart'), isTrue); |
| + expect(glob.matches(r'()[]{}.dart'), isTrue); |
| + expect(glob.matches('\u2665.dart'), isTrue); |
| + } |
| + |
| + void test_star() { |
| + Glob glob = new Glob(r'/', r'web/*.dart'); |
| + expect(glob.matches(r'web/foo.dart'), isTrue); |
| + expect(glob.matches(r'web/barbaz.dart'), isTrue); |
| + // does not end with 'dart' |
| + expect(glob.matches(r'web/foo.html'), isFalse); |
| + // not in 'web' |
| + expect(glob.matches(r'lib/foo.dart'), isFalse); |
| + expect(glob.matches(r'/web/foo.dart'), isFalse); |
| + // in sub-folder |
| + expect(glob.matches(r'web/sub/foo.dart'), isFalse); |
| + } |
| + |
| + void test_starStar() { |
| + Glob glob = new Glob(r'/', r'**.dart'); |
| + expect(glob.matches(r'foo/bar.dart'), isTrue); |
| + expect(glob.matches(r'foo/bar/baz.dart'), isTrue); |
| + // does not end with 'dart' |
| + expect(glob.matches(r'web/foo.html'), isFalse); |
| + } |
| +} |
| + |
| +@reflectiveTest |
| +class GlobWindowsTest { |
|
Brian Wilkerson
2015/11/15 16:27:47
None of the paths in these tests contain drive let
scheglov
2015/11/15 18:42:11
Done.
|
| + void test_case() { |
| + Glob glob = new Glob(r'\', r'**.dart'); |
| + expect(glob.matches(r'aaa.dart'), isTrue); |
| + expect(glob.matches(r'bbb.DART'), isTrue); |
| + expect(glob.matches(r'ccc.dArT'), isTrue); |
| + expect(glob.matches(r'ddd.DaRt'), isTrue); |
| + } |
| + |
| + void test_question() { |
| + Glob glob = new Glob(r'\', r'?.dart'); |
| + expect(glob.matches(r'a.dart'), isTrue); |
| + expect(glob.matches(r'b.dart'), isTrue); |
| + expect(glob.matches(r'cc.dart'), isFalse); |
| + } |
| + |
| + void test_specialChars() { |
| + Glob glob = new Glob(r'\', r'*.dart'); |
| + expect(glob.matches(r'a.dart'), isTrue); |
| + expect(glob.matches('_-\a.dart'), isTrue); |
| + expect(glob.matches(r'^$*?.dart'), isTrue); |
| + expect(glob.matches(r'()[]{}.dart'), isTrue); |
| + expect(glob.matches('\u2665.dart'), isTrue); |
| + } |
| + |
| + void test_star() { |
| + Glob glob = new Glob(r'\', r'web/*.dart'); |
| + expect(glob.matches(r'web\foo.dart'), isTrue); |
| + expect(glob.matches(r'web\barbaz.dart'), isTrue); |
| + // does not end with 'dart' |
| + expect(glob.matches(r'web\foo.html'), isFalse); |
| + // not in 'web' |
| + expect(glob.matches(r'lib\foo.dart'), isFalse); |
| + expect(glob.matches(r'\web\foo.dart'), isFalse); |
| + // in sub-folder |
| + expect(glob.matches(r'web\sub\foo.dart'), isFalse); |
| + } |
| + |
| + void test_starStar() { |
| + Glob glob = new Glob(r'\', r'**.dart'); |
| + expect(glob.matches(r'foo\bar.dart'), isTrue); |
| + expect(glob.matches(r'foo\bar\baz.dart'), isTrue); |
| + // does not end with 'dart' |
| + expect(glob.matches(r'web\foo.html'), isFalse); |
| + } |
| +} |