Chromium Code Reviews

Side by Side Diff: packages/quiver/test/pattern/glob_test.dart

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
OLDNEW
(Empty)
1 // Copyright 2013 Google Inc. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 library quiver.patttern.glob_test;
16
17 import 'package:test/test.dart';
18 import 'package:quiver/pattern.dart';
19
20 main() {
21 group('Glob', () {
22 test('should match "*" against sequences of word chars', () {
23 expectGlob("*.html",
24 matches: [
25 "a.html",
26 "_-\a.html",
27 r"^$*?.html",
28 "()[]{}.html",
29 "↭.html",
30 "\u21ad.html",
31 "♥.html",
32 "\u2665.html"
33 ],
34 nonMatches: ["a.htm", "a.htmlx", "/a.html"]);
35 expectGlob("foo.*",
36 matches: ["foo.html"],
37 nonMatches: ["afoo.html", "foo/a.html", "foo.html/a"]);
38 });
39
40 test('should match "**" against paths', () {
41 expectGlob("**/*.html",
42 matches: ["/a.html", "a/b.html", "a/b/c.html", "a/b/c.html/d.html"],
43 nonMatches: ["a.html", "a/b.html/c"]);
44 });
45
46 test('should match "?" a single word char', () {
47 expectGlob("a?",
48 matches: ["ab", "a?", "a↭", "a\u21ad", "a\\"],
49 nonMatches: ["a", "abc"]);
50 });
51 });
52 }
53
54 expectGlob(String pattern, {List<String> matches, List<String> nonMatches}) {
55 var glob = new Glob(pattern);
56 for (var str in matches) {
57 expect(glob.hasMatch(str), true);
58 expect(glob.allMatches(str).map((m) => m.input), [str]);
59 var match = glob.matchAsPrefix(str);
60 expect(match.start, 0);
61 expect(match.end, str.length);
62 }
63 for (var str in nonMatches) {
64 expect(glob.hasMatch(str), false);
65 var m = new List.from(glob.allMatches(str));
66 expect(m.length, 0);
67 expect(glob.matchAsPrefix(str), null);
68 }
69 }
OLDNEW
« no previous file with comments | « packages/quiver/test/pattern/all_tests.dart ('k') | packages/quiver/test/pattern/pattern_test.dart » ('j') | no next file with comments »

Powered by Google App Engine