diff options
author | Ondřej Surý <ondrej@sury.org> | 2012-03-26 16:50:58 +0200 |
---|---|---|
committer | Ondřej Surý <ondrej@sury.org> | 2012-03-26 16:50:58 +0200 |
commit | 519725bb3c075ee2462c929f5997cb068e18466a (patch) | |
tree | 5b162e8488ad147a645048c073577821b4a2bee9 /src/pkg/path/filepath/match_test.go | |
parent | 842623c5dd2819d980ca9c58048d6bc6ed82475f (diff) | |
download | golang-upstream-weekly/2012.03.22.tar.gz |
Imported Upstream version 2012.03.22upstream-weekly/2012.03.22
Diffstat (limited to 'src/pkg/path/filepath/match_test.go')
-rw-r--r-- | src/pkg/path/filepath/match_test.go | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/src/pkg/path/filepath/match_test.go b/src/pkg/path/filepath/match_test.go index 7bdc449bc..7b0ea8017 100644 --- a/src/pkg/path/filepath/match_test.go +++ b/src/pkg/path/filepath/match_test.go @@ -7,6 +7,7 @@ package filepath_test import ( . "path/filepath" "runtime" + "strings" "testing" ) @@ -76,21 +77,26 @@ func errp(e error) string { } func TestMatch(t *testing.T) { - if runtime.GOOS == "windows" { - // XXX: Don't pass for windows. - return - } for _, tt := range matchTests { - ok, err := Match(tt.pattern, tt.s) + pattern := tt.pattern + s := tt.s + if runtime.GOOS == "windows" { + if strings.Index(pattern, "\\") >= 0 { + // no escape allowed on windows. + continue + } + pattern = Clean(pattern) + s = Clean(s) + } + ok, err := Match(pattern, s) if ok != tt.match || err != tt.err { - t.Errorf("Match(%#q, %#q) = %v, %q want %v, %q", tt.pattern, tt.s, ok, errp(err), tt.match, errp(tt.err)) + t.Errorf("Match(%#q, %#q) = %v, %q want %v, %q", pattern, s, ok, errp(err), tt.match, errp(tt.err)) } } } // contains returns true if vector contains the string s. func contains(vector []string, s string) bool { - s = ToSlash(s) for _, elem := range vector { if elem == s { return true @@ -109,18 +115,20 @@ var globTests = []struct { } func TestGlob(t *testing.T) { - if runtime.GOOS == "windows" { - // XXX: Don't pass for windows. - return - } for _, tt := range globTests { - matches, err := Glob(tt.pattern) + pattern := tt.pattern + result := tt.result + if runtime.GOOS == "windows" { + pattern = Clean(pattern) + result = Clean(result) + } + matches, err := Glob(pattern) if err != nil { - t.Errorf("Glob error for %q: %s", tt.pattern, err) + t.Errorf("Glob error for %q: %s", pattern, err) continue } - if !contains(matches, tt.result) { - t.Errorf("Glob(%#q) = %#v want %v", tt.pattern, matches, tt.result) + if !contains(matches, result) { + t.Errorf("Glob(%#q) = %#v want %v", pattern, matches, result) } } for _, pattern := range []string{"no_match", "../*/no_match"} { |