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

Side by Side Diff: pkg/glob/test/glob_test.dart

Issue 506993004: Create a glob package. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 months 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2014, 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 import 'package:glob/glob.dart';
6 import 'package:unittest/unittest.dart';
7
8 void main() {
9 group("Glob.quote()", () {
10 test("quotes all active characters", () {
11 expect(Glob.quote("*{[?\\}],-"), equals(r"\*\{\[\?\\\}\]\,\-"));
12 });
13
14 test("doesn't quote inactive characters", () {
15 expect(Glob.quote("abc~`_+="), equals("abc~`_+="));
16 });
17 });
18
19 group("Glob.matches()", () {
20 test("returns whether the path matches the glob", () {
21 var glob = new Glob("foo*");
22 expect(glob.matches("foobar"), isTrue);
23 expect(glob.matches("baz"), isFalse);
24 });
25
26 test("only matches the entire path", () {
27 var glob = new Glob("foo");
28 expect(glob.matches("foo/bar"), isFalse);
29 expect(glob.matches("bar/foo"), isFalse);
30 });
31 });
32
33 group("Glob.matchAsPrefix()", () {
34 test("returns a match if the path matches the glob", () {
35 var glob = new Glob("foo*");
36 expect(glob.matchAsPrefix("foobar"), new isInstanceOf<Match>());
37 expect(glob.matchAsPrefix("baz"), isNull);
38 });
39
40 test("returns null for start > 0", () {
41 var glob = new Glob("*");
42 expect(glob.matchAsPrefix("foobar", 1), isNull);
43 });
44 });
45
46 group("Glob.allMatches()", () {
47 test("returns a single match if the path matches the glob", () {
48 var glob = new Glob("foo*");
49 var matches = glob.allMatches("foobar");
50 expect(matches, hasLength(1));
51 expect(matches.first, new isInstanceOf<Match>());
52 expect(glob.allMatches("baz"), isEmpty);
53 });
54
Bob Nystrom 2014/08/27 22:16:44 Test that it returns an empty collection if it doe
55 test("returns no matches for start > 0", () {
56 var glob = new Glob("*");
57 expect(glob.allMatches("foobar", 1), isEmpty);
58 });
59 });
60
61 group("GlobMatch", () {
62 var glob = new Glob("foo*");
63 var match = glob.matchAsPrefix("foobar");
64
65 test("returns the string as input", () {
66 expect(match.input, equals("foobar"));
67 });
68
69 test("returns the glob as the pattern", () {
70 expect(match.pattern, equals(glob));
71 });
72
73 test("returns the span of the string for start and end", () {
74 expect(match.start, equals(0));
75 expect(match.end, equals("foobar".length));
76 });
77
78 test("has a single group that contains the whole string", () {
79 expect(match.groupCount, equals(0));
80 expect(match[0], equals("foobar"));
81 expect(match.group(0), equals("foobar"));
82 expect(match.groups([0]), equals(["foobar"]));
83 });
84
85 test("throws a range error for an invalid group", () {
86 expect(() => match[1], throwsRangeError);
87 expect(() => match[-1], throwsRangeError);
88 expect(() => match.group(1), throwsRangeError);
89 expect(() => match.groups([1]), throwsRangeError);
90 });
91 });
92 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698