Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(981)

Unified Diff: pkg/analyzer/test/src/util/glob_test.dart

Issue 1452473002: Replace Glob implementation. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Tweaks for review comments. Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analyzer/lib/src/util/glob.dart ('k') | pkg/analyzer/test/src/util/test_all.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..d3bc531ccfd6b09213ed5c89953da835f699194e
--- /dev/null
+++ b/pkg/analyzer/test/src/util/glob_test.dart
@@ -0,0 +1,115 @@
+// 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_specialChars2() {
+ Glob glob = new Glob(r'/', r'a[]b.dart');
+ expect(glob.matches(r'a[]b.dart'), isTrue);
+ expect(glob.matches(r'aNb.dart'), isFalse);
+ }
+
+ 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);
+ 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 {
+ 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);
+ expect(glob.matches(r'C:\foo\bar.dart'), isTrue);
+ expect(glob.matches(r'C:\foo\bar\baz.dart'), isTrue);
+ // does not end with 'dart'
+ expect(glob.matches(r'C:\web\foo.html'), isFalse);
+ }
+}
« no previous file with comments | « pkg/analyzer/lib/src/util/glob.dart ('k') | pkg/analyzer/test/src/util/test_all.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698