| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2015, 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 library test.analyzer.src.util.glob; |
| 6 |
| 7 import 'package:analyzer/src/util/glob.dart'; |
| 8 import 'package:unittest/unittest.dart'; |
| 9 |
| 10 import '../../reflective_tests.dart'; |
| 11 import '../../utils.dart'; |
| 12 |
| 13 main() { |
| 14 initializeTestEnvironment(); |
| 15 runReflectiveTests(GlobPosixTest); |
| 16 runReflectiveTests(GlobWindowsTest); |
| 17 } |
| 18 |
| 19 @reflectiveTest |
| 20 class GlobPosixTest { |
| 21 void test_question() { |
| 22 Glob glob = new Glob(r'/', r'?.dart'); |
| 23 expect(glob.matches(r'a.dart'), isTrue); |
| 24 expect(glob.matches(r'b.dart'), isTrue); |
| 25 expect(glob.matches(r'cc.dart'), isFalse); |
| 26 } |
| 27 |
| 28 void test_specialChars() { |
| 29 Glob glob = new Glob(r'/', r'*.dart'); |
| 30 expect(glob.matches(r'a.dart'), isTrue); |
| 31 expect(glob.matches('_-\a.dart'), isTrue); |
| 32 expect(glob.matches(r'^$*?.dart'), isTrue); |
| 33 expect(glob.matches(r'()[]{}.dart'), isTrue); |
| 34 expect(glob.matches('\u2665.dart'), isTrue); |
| 35 } |
| 36 |
| 37 void test_specialChars2() { |
| 38 Glob glob = new Glob(r'/', r'a[]b.dart'); |
| 39 expect(glob.matches(r'a[]b.dart'), isTrue); |
| 40 expect(glob.matches(r'aNb.dart'), isFalse); |
| 41 } |
| 42 |
| 43 void test_star() { |
| 44 Glob glob = new Glob(r'/', r'web/*.dart'); |
| 45 expect(glob.matches(r'web/foo.dart'), isTrue); |
| 46 expect(glob.matches(r'web/barbaz.dart'), isTrue); |
| 47 // does not end with 'dart' |
| 48 expect(glob.matches(r'web/foo.html'), isFalse); |
| 49 // not in 'web' |
| 50 expect(glob.matches(r'lib/foo.dart'), isFalse); |
| 51 expect(glob.matches(r'/web/foo.dart'), isFalse); |
| 52 // in sub-folder |
| 53 expect(glob.matches(r'web/sub/foo.dart'), isFalse); |
| 54 } |
| 55 |
| 56 void test_starStar() { |
| 57 Glob glob = new Glob(r'/', r'**.dart'); |
| 58 expect(glob.matches(r'foo/bar.dart'), isTrue); |
| 59 expect(glob.matches(r'foo/bar/baz.dart'), isTrue); |
| 60 expect(glob.matches(r'/foo/bar.dart'), isTrue); |
| 61 expect(glob.matches(r'/foo/bar/baz.dart'), isTrue); |
| 62 // does not end with 'dart' |
| 63 expect(glob.matches(r'/web/foo.html'), isFalse); |
| 64 } |
| 65 } |
| 66 |
| 67 @reflectiveTest |
| 68 class GlobWindowsTest { |
| 69 void test_case() { |
| 70 Glob glob = new Glob(r'\', r'**.dart'); |
| 71 expect(glob.matches(r'aaa.dart'), isTrue); |
| 72 expect(glob.matches(r'bbb.DART'), isTrue); |
| 73 expect(glob.matches(r'ccc.dArT'), isTrue); |
| 74 expect(glob.matches(r'ddd.DaRt'), isTrue); |
| 75 } |
| 76 |
| 77 void test_question() { |
| 78 Glob glob = new Glob(r'\', r'?.dart'); |
| 79 expect(glob.matches(r'a.dart'), isTrue); |
| 80 expect(glob.matches(r'b.dart'), isTrue); |
| 81 expect(glob.matches(r'cc.dart'), isFalse); |
| 82 } |
| 83 |
| 84 void test_specialChars() { |
| 85 Glob glob = new Glob(r'\', r'*.dart'); |
| 86 expect(glob.matches(r'a.dart'), isTrue); |
| 87 expect(glob.matches('_-\a.dart'), isTrue); |
| 88 expect(glob.matches(r'^$*?.dart'), isTrue); |
| 89 expect(glob.matches(r'()[]{}.dart'), isTrue); |
| 90 expect(glob.matches('\u2665.dart'), isTrue); |
| 91 } |
| 92 |
| 93 void test_star() { |
| 94 Glob glob = new Glob(r'\', r'web/*.dart'); |
| 95 expect(glob.matches(r'web\foo.dart'), isTrue); |
| 96 expect(glob.matches(r'web\barbaz.dart'), isTrue); |
| 97 // does not end with 'dart' |
| 98 expect(glob.matches(r'web\foo.html'), isFalse); |
| 99 // not in 'web' |
| 100 expect(glob.matches(r'lib\foo.dart'), isFalse); |
| 101 expect(glob.matches(r'\web\foo.dart'), isFalse); |
| 102 // in sub-folder |
| 103 expect(glob.matches(r'web\sub\foo.dart'), isFalse); |
| 104 } |
| 105 |
| 106 void test_starStar() { |
| 107 Glob glob = new Glob(r'\', r'**.dart'); |
| 108 expect(glob.matches(r'foo\bar.dart'), isTrue); |
| 109 expect(glob.matches(r'foo\bar\baz.dart'), isTrue); |
| 110 expect(glob.matches(r'C:\foo\bar.dart'), isTrue); |
| 111 expect(glob.matches(r'C:\foo\bar\baz.dart'), isTrue); |
| 112 // does not end with 'dart' |
| 113 expect(glob.matches(r'C:\web\foo.html'), isFalse); |
| 114 } |
| 115 } |
| OLD | NEW |