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