OLD | NEW |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package filepath_test | 5 package filepath_test |
6 | 6 |
7 import ( | 7 import ( |
8 "os" | |
9 . "path/filepath" | 8 . "path/filepath" |
10 "testing" | 9 "testing" |
11 "runtime" | 10 "runtime" |
12 ) | 11 ) |
13 | 12 |
14 type MatchTest struct { | 13 type MatchTest struct { |
15 pattern, s string | 14 pattern, s string |
16 match bool | 15 match bool |
17 » err os.Error | 16 » err error |
18 } | 17 } |
19 | 18 |
20 var matchTests = []MatchTest{ | 19 var matchTests = []MatchTest{ |
21 {"abc", "abc", true, nil}, | 20 {"abc", "abc", true, nil}, |
22 {"*", "abc", true, nil}, | 21 {"*", "abc", true, nil}, |
23 {"*c", "abc", true, nil}, | 22 {"*c", "abc", true, nil}, |
24 {"a*", "a", true, nil}, | 23 {"a*", "a", true, nil}, |
25 {"a*", "abc", true, nil}, | 24 {"a*", "abc", true, nil}, |
26 {"a*", "ab/c", false, nil}, | 25 {"a*", "ab/c", false, nil}, |
27 {"a*/b", "abc/b", true, nil}, | 26 {"a*/b", "abc/b", true, nil}, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 {"[x-]", "-", false, ErrBadPattern}, | 61 {"[x-]", "-", false, ErrBadPattern}, |
63 {"[x-]", "z", false, ErrBadPattern}, | 62 {"[x-]", "z", false, ErrBadPattern}, |
64 {"[-x]", "x", false, ErrBadPattern}, | 63 {"[-x]", "x", false, ErrBadPattern}, |
65 {"[-x]", "-", false, ErrBadPattern}, | 64 {"[-x]", "-", false, ErrBadPattern}, |
66 {"[-x]", "a", false, ErrBadPattern}, | 65 {"[-x]", "a", false, ErrBadPattern}, |
67 {"\\", "a", false, ErrBadPattern}, | 66 {"\\", "a", false, ErrBadPattern}, |
68 {"[a-b-c]", "a", false, ErrBadPattern}, | 67 {"[a-b-c]", "a", false, ErrBadPattern}, |
69 {"*x", "xxx", true, nil}, | 68 {"*x", "xxx", true, nil}, |
70 } | 69 } |
71 | 70 |
72 func errp(e os.Error) string { | 71 func errp(e error) string { |
73 if e == nil { | 72 if e == nil { |
74 return "<nil>" | 73 return "<nil>" |
75 } | 74 } |
76 » return e.String() | 75 » return e.Error() |
77 } | 76 } |
78 | 77 |
79 func TestMatch(t *testing.T) { | 78 func TestMatch(t *testing.T) { |
80 if runtime.GOOS == "windows" { | 79 if runtime.GOOS == "windows" { |
81 // XXX: Don't pass for windows. | 80 // XXX: Don't pass for windows. |
82 return | 81 return |
83 } | 82 } |
84 for _, tt := range matchTests { | 83 for _, tt := range matchTests { |
85 ok, err := Match(tt.pattern, tt.s) | 84 ok, err := Match(tt.pattern, tt.s) |
86 if ok != tt.match || err != tt.err { | 85 if ok != tt.match || err != tt.err { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 } | 134 } |
136 } | 135 } |
137 } | 136 } |
138 | 137 |
139 func TestGlobError(t *testing.T) { | 138 func TestGlobError(t *testing.T) { |
140 _, err := Glob("[7]") | 139 _, err := Glob("[7]") |
141 if err != nil { | 140 if err != nil { |
142 t.Error("expected error for bad pattern; got none") | 141 t.Error("expected error for bad pattern; got none") |
143 } | 142 } |
144 } | 143 } |
OLD | NEW |