OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [go/] [path/] [filepath/] [match_test.go] - Blame information for rev 747

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 747 jeremybenn
// Copyright 2009 The Go Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
4
 
5
package filepath_test
6
 
7
import (
8
        . "path/filepath"
9
        "runtime"
10
        "testing"
11
)
12
 
13
type MatchTest struct {
14
        pattern, s string
15
        match      bool
16
        err        error
17
}
18
 
19
var matchTests = []MatchTest{
20
        {"abc", "abc", true, nil},
21
        {"*", "abc", true, nil},
22
        {"*c", "abc", true, nil},
23
        {"a*", "a", true, nil},
24
        {"a*", "abc", true, nil},
25
        {"a*", "ab/c", false, nil},
26
        {"a*/b", "abc/b", true, nil},
27
        {"a*/b", "a/c/b", false, nil},
28
        {"a*b*c*d*e*/f", "axbxcxdxe/f", true, nil},
29
        {"a*b*c*d*e*/f", "axbxcxdxexxx/f", true, nil},
30
        {"a*b*c*d*e*/f", "axbxcxdxe/xxx/f", false, nil},
31
        {"a*b*c*d*e*/f", "axbxcxdxexxx/fff", false, nil},
32
        {"a*b?c*x", "abxbbxdbxebxczzx", true, nil},
33
        {"a*b?c*x", "abxbbxdbxebxczzy", false, nil},
34
        {"ab[c]", "abc", true, nil},
35
        {"ab[b-d]", "abc", true, nil},
36
        {"ab[e-g]", "abc", false, nil},
37
        {"ab[^c]", "abc", false, nil},
38
        {"ab[^b-d]", "abc", false, nil},
39
        {"ab[^e-g]", "abc", true, nil},
40
        {"a\\*b", "a*b", true, nil},
41
        {"a\\*b", "ab", false, nil},
42
        {"a?b", "a☺b", true, nil},
43
        {"a[^a]b", "a☺b", true, nil},
44
        {"a???b", "a☺b", false, nil},
45
        {"a[^a][^a][^a]b", "a☺b", false, nil},
46
        {"[a-ζ]*", "α", true, nil},
47
        {"*[a-ζ]", "A", false, nil},
48
        {"a?b", "a/b", false, nil},
49
        {"a*b", "a/b", false, nil},
50
        {"[\\]a]", "]", true, nil},
51
        {"[\\-]", "-", true, nil},
52
        {"[x\\-]", "x", true, nil},
53
        {"[x\\-]", "-", true, nil},
54
        {"[x\\-]", "z", false, nil},
55
        {"[\\-x]", "x", true, nil},
56
        {"[\\-x]", "-", true, nil},
57
        {"[\\-x]", "a", false, nil},
58
        {"[]a]", "]", false, ErrBadPattern},
59
        {"[-]", "-", false, ErrBadPattern},
60
        {"[x-]", "x", false, ErrBadPattern},
61
        {"[x-]", "-", false, ErrBadPattern},
62
        {"[x-]", "z", false, ErrBadPattern},
63
        {"[-x]", "x", false, ErrBadPattern},
64
        {"[-x]", "-", false, ErrBadPattern},
65
        {"[-x]", "a", false, ErrBadPattern},
66
        {"\\", "a", false, ErrBadPattern},
67
        {"[a-b-c]", "a", false, ErrBadPattern},
68
        {"*x", "xxx", true, nil},
69
}
70
 
71
func errp(e error) string {
72
        if e == nil {
73
                return ""
74
        }
75
        return e.Error()
76
}
77
 
78
func TestMatch(t *testing.T) {
79
        if runtime.GOOS == "windows" {
80
                // XXX: Don't pass for windows.
81
                return
82
        }
83
        for _, tt := range matchTests {
84
                ok, err := Match(tt.pattern, tt.s)
85
                if ok != tt.match || err != tt.err {
86
                        t.Errorf("Match(%#q, %#q) = %v, %q want %v, %q", tt.pattern, tt.s, ok, errp(err), tt.match, errp(tt.err))
87
                }
88
        }
89
}
90
 
91
// contains returns true if vector contains the string s.
92
func contains(vector []string, s string) bool {
93
        s = ToSlash(s)
94
        for _, elem := range vector {
95
                if elem == s {
96
                        return true
97
                }
98
        }
99
        return false
100
}
101
 
102
var globTests = []struct {
103
        pattern, result string
104
}{
105
        {"match.go", "match.go"},
106
        {"mat?h.go", "match.go"},
107
        {"*", "match.go"},
108
        // Does not work in gccgo test environment.
109
        // {"../*/match.go", "../filepath/match.go"},
110
}
111
 
112
func TestGlob(t *testing.T) {
113
        if runtime.GOOS == "windows" {
114
                // XXX: Don't pass for windows.
115
                return
116
        }
117
        for _, tt := range globTests {
118
                matches, err := Glob(tt.pattern)
119
                if err != nil {
120
                        t.Errorf("Glob error for %q: %s", tt.pattern, err)
121
                        continue
122
                }
123
                if !contains(matches, tt.result) {
124
                        t.Errorf("Glob(%#q) = %#v want %v", tt.pattern, matches, tt.result)
125
                }
126
        }
127
        for _, pattern := range []string{"no_match", "../*/no_match"} {
128
                matches, err := Glob(pattern)
129
                if err != nil {
130
                        t.Errorf("Glob error for %q: %s", pattern, err)
131
                        continue
132
                }
133
                if len(matches) != 0 {
134
                        t.Errorf("Glob(%#q) = %#v want []", pattern, matches)
135
                }
136
        }
137
}
138
 
139
func TestGlobError(t *testing.T) {
140
        _, err := Glob("[7]")
141
        if err != nil {
142
                t.Error("expected error for bad pattern; got none")
143
        }
144
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.