OLD | NEW |
(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:test/test.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 matches = new Glob("foo*").allMatches("foobar"); |
| 49 expect(matches, hasLength(1)); |
| 50 expect(matches.first, new isInstanceOf<Match>()); |
| 51 }); |
| 52 |
| 53 test("returns an empty list if the path doesn't match the glob", () { |
| 54 expect(new Glob("foo*").allMatches("baz"), isEmpty); |
| 55 }); |
| 56 |
| 57 test("returns no matches for start > 0", () { |
| 58 var glob = new Glob("*"); |
| 59 expect(glob.allMatches("foobar", 1), isEmpty); |
| 60 }); |
| 61 }); |
| 62 |
| 63 group("GlobMatch", () { |
| 64 var glob = new Glob("foo*"); |
| 65 var match = glob.matchAsPrefix("foobar"); |
| 66 |
| 67 test("returns the string as input", () { |
| 68 expect(match.input, equals("foobar")); |
| 69 }); |
| 70 |
| 71 test("returns the glob as the pattern", () { |
| 72 expect(match.pattern, equals(glob)); |
| 73 }); |
| 74 |
| 75 test("returns the span of the string for start and end", () { |
| 76 expect(match.start, equals(0)); |
| 77 expect(match.end, equals("foobar".length)); |
| 78 }); |
| 79 |
| 80 test("has a single group that contains the whole string", () { |
| 81 expect(match.groupCount, equals(0)); |
| 82 expect(match[0], equals("foobar")); |
| 83 expect(match.group(0), equals("foobar")); |
| 84 expect(match.groups([0]), equals(["foobar"])); |
| 85 }); |
| 86 |
| 87 test("throws a range error for an invalid group", () { |
| 88 expect(() => match[1], throwsRangeError); |
| 89 expect(() => match[-1], throwsRangeError); |
| 90 expect(() => match.group(1), throwsRangeError); |
| 91 expect(() => match.groups([1]), throwsRangeError); |
| 92 }); |
| 93 }); |
| 94 } |
OLD | NEW |