Fix glob match and parse tests for Windows and URL styles.
R=rnystrom@google.com
BUG=20788, 20789
Review URL: https://codereview.chromium.org//533323003
git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@39922 260f80e4-7a28-3924-810f-c04153c831b5
diff --git a/test/match_test.dart b/test/match_test.dart
index eeb307d..ad9dcf3 100644
--- a/test/match_test.dart
+++ b/test/match_test.dart
@@ -6,8 +6,12 @@
import 'package:path/path.dart' as p;
import 'package:unittest/unittest.dart';
-const ASCII_WITHOUT_SLASH = "\t\n\r !\"#\$%&'()*+`-.0123456789:;<=>?@ABCDEFGHIJ"
- "KLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
+const RAW_ASCII_WITHOUT_SLASH = "\t\n\r !\"#\$%&'()*+`-.0123456789:;<=>?@ABCDEF"
+ "GHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~";
+
+// URL-encode the path for a URL context.
+final asciiWithoutSlash = p.style == p.Style.url ?
+ Uri.encodeFull(RAW_ASCII_WITHOUT_SLASH) : RAW_ASCII_WITHOUT_SLASH;
void main() {
test("literals match exactly", () {
@@ -16,10 +20,15 @@
expect("foo*", contains(new Glob(r"foo\*")));
});
+ test("backslashes match nothing on Windows", () {
+ expect(r"foo\bar",
+ isNot(contains(new Glob(r"foo\\bar", context: p.windows))));
+ });
+
group("star", () {
test("matches non-separator characters", () {
var glob = new Glob("*");
- expect(ASCII_WITHOUT_SLASH, contains(glob));
+ expect(asciiWithoutSlash, contains(glob));
});
test("matches the empty string", () {
@@ -36,7 +45,7 @@
group("double star", () {
test("matches non-separator characters", () {
var glob = new Glob("**");
- expect(ASCII_WITHOUT_SLASH, contains(glob));
+ expect(asciiWithoutSlash, contains(glob));
});
test("matches the empty string", () {
@@ -65,7 +74,8 @@
group("any char", () {
test("matches any non-separator character", () {
var glob = new Glob("foo?");
- for (var char in ASCII_WITHOUT_SLASH.split('')) {
+ for (var char in RAW_ASCII_WITHOUT_SLASH.split('')) {
+ if (p.style == p.Style.url) char = Uri.encodeFull(char);
expect("foo$char", contains(glob));
}
});
diff --git a/test/parse_test.dart b/test/parse_test.dart
index 5ea3f05..fcaa5b4 100644
--- a/test/parse_test.dart
+++ b/test/parse_test.dart
@@ -3,11 +3,15 @@
// BSD-style license that can be found in the LICENSE file.
import 'package:glob/glob.dart';
+import 'package:path/path.dart' as p;
import 'package:unittest/unittest.dart';
void main() {
test("supports backslash-escaped characters", () {
expect(r"\*[]{,}?()", contains(new Glob(r"\\\*\[\]\{\,\}\?\(\)")));
+ if (p.style != p.Style.windows) {
+ expect(r"foo\bar", contains(new Glob(r"foo\\bar")));
+ }
});
test("disallows an empty glob", () {