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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [go/] [path/] [path_test.go] - Blame information for rev 867

Go to most recent revision | 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 path
6
 
7
import (
8
        "testing"
9
)
10
 
11
type PathTest struct {
12
        path, result string
13
}
14
 
15
var cleantests = []PathTest{
16
        // Already clean
17
        {"", "."},
18
        {"abc", "abc"},
19
        {"abc/def", "abc/def"},
20
        {"a/b/c", "a/b/c"},
21
        {".", "."},
22
        {"..", ".."},
23
        {"../..", "../.."},
24
        {"../../abc", "../../abc"},
25
        {"/abc", "/abc"},
26
        {"/", "/"},
27
 
28
        // Remove trailing slash
29
        {"abc/", "abc"},
30
        {"abc/def/", "abc/def"},
31
        {"a/b/c/", "a/b/c"},
32
        {"./", "."},
33
        {"../", ".."},
34
        {"../../", "../.."},
35
        {"/abc/", "/abc"},
36
 
37
        // Remove doubled slash
38
        {"abc//def//ghi", "abc/def/ghi"},
39
        {"//abc", "/abc"},
40
        {"///abc", "/abc"},
41
        {"//abc//", "/abc"},
42
        {"abc//", "abc"},
43
 
44
        // Remove . elements
45
        {"abc/./def", "abc/def"},
46
        {"/./abc/def", "/abc/def"},
47
        {"abc/.", "abc"},
48
 
49
        // Remove .. elements
50
        {"abc/def/ghi/../jkl", "abc/def/jkl"},
51
        {"abc/def/../ghi/../jkl", "abc/jkl"},
52
        {"abc/def/..", "abc"},
53
        {"abc/def/../..", "."},
54
        {"/abc/def/../..", "/"},
55
        {"abc/def/../../..", ".."},
56
        {"/abc/def/../../..", "/"},
57
        {"abc/def/../../../ghi/jkl/../../../mno", "../../mno"},
58
 
59
        // Combinations
60
        {"abc/./../def", "def"},
61
        {"abc//./../def", "def"},
62
        {"abc/../../././../def", "../../def"},
63
}
64
 
65
func TestClean(t *testing.T) {
66
        for _, test := range cleantests {
67
                if s := Clean(test.path); s != test.result {
68
                        t.Errorf("Clean(%q) = %q, want %q", test.path, s, test.result)
69
                }
70
        }
71
}
72
 
73
type SplitTest struct {
74
        path, dir, file string
75
}
76
 
77
var splittests = []SplitTest{
78
        {"a/b", "a/", "b"},
79
        {"a/b/", "a/b/", ""},
80
        {"a/", "a/", ""},
81
        {"a", "", "a"},
82
        {"/", "/", ""},
83
}
84
 
85
func TestSplit(t *testing.T) {
86
        for _, test := range splittests {
87
                if d, f := Split(test.path); d != test.dir || f != test.file {
88
                        t.Errorf("Split(%q) = %q, %q, want %q, %q", test.path, d, f, test.dir, test.file)
89
                }
90
        }
91
}
92
 
93
type JoinTest struct {
94
        elem []string
95
        path string
96
}
97
 
98
var jointests = []JoinTest{
99
        // zero parameters
100
        {[]string{}, ""},
101
 
102
        // one parameter
103
        {[]string{""}, ""},
104
        {[]string{"a"}, "a"},
105
 
106
        // two parameters
107
        {[]string{"a", "b"}, "a/b"},
108
        {[]string{"a", ""}, "a"},
109
        {[]string{"", "b"}, "b"},
110
        {[]string{"/", "a"}, "/a"},
111
        {[]string{"/", ""}, "/"},
112
        {[]string{"a/", "b"}, "a/b"},
113
        {[]string{"a/", ""}, "a"},
114
        {[]string{"", ""}, ""},
115
}
116
 
117
// join takes a []string and passes it to Join.
118
func join(elem []string, args ...string) string {
119
        args = elem
120
        return Join(args...)
121
}
122
 
123
func TestJoin(t *testing.T) {
124
        for _, test := range jointests {
125
                if p := join(test.elem); p != test.path {
126
                        t.Errorf("join(%q) = %q, want %q", test.elem, p, test.path)
127
                }
128
        }
129
}
130
 
131
type ExtTest struct {
132
        path, ext string
133
}
134
 
135
var exttests = []ExtTest{
136
        {"path.go", ".go"},
137
        {"path.pb.go", ".go"},
138
        {"a.dir/b", ""},
139
        {"a.dir/b.go", ".go"},
140
        {"a.dir/", ""},
141
}
142
 
143
func TestExt(t *testing.T) {
144
        for _, test := range exttests {
145
                if x := Ext(test.path); x != test.ext {
146
                        t.Errorf("Ext(%q) = %q, want %q", test.path, x, test.ext)
147
                }
148
        }
149
}
150
 
151
var basetests = []PathTest{
152
        // Already clean
153
        {"", "."},
154
        {".", "."},
155
        {"/.", "."},
156
        {"/", "/"},
157
        {"////", "/"},
158
        {"x/", "x"},
159
        {"abc", "abc"},
160
        {"abc/def", "def"},
161
        {"a/b/.x", ".x"},
162
        {"a/b/c.", "c."},
163
        {"a/b/c.x", "c.x"},
164
}
165
 
166
func TestBase(t *testing.T) {
167
        for _, test := range basetests {
168
                if s := Base(test.path); s != test.result {
169
                        t.Errorf("Base(%q) = %q, want %q", test.path, s, test.result)
170
                }
171
        }
172
}
173
 
174
var dirtests = []PathTest{
175
        {"", "."},
176
        {".", "."},
177
        {"/.", "/"},
178
        {"/", "/"},
179
        {"////", "/"},
180
        {"/foo", "/"},
181
        {"x/", "x"},
182
        {"abc", "."},
183
        {"abc/def", "abc"},
184
        {"a/b/.x", "a/b"},
185
        {"a/b/c.", "a/b"},
186
        {"a/b/c.x", "a/b"},
187
}
188
 
189
func TestDir(t *testing.T) {
190
        for _, test := range dirtests {
191
                if s := Dir(test.path); s != test.result {
192
                        t.Errorf("Dir(%q) = %q, want %q", test.path, s, test.result)
193
                }
194
        }
195
}
196
 
197
type IsAbsTest struct {
198
        path  string
199
        isAbs bool
200
}
201
 
202
var isAbsTests = []IsAbsTest{
203
        {"", false},
204
        {"/", true},
205
        {"/usr/bin/gcc", true},
206
        {"..", false},
207
        {"/a/../bb", true},
208
        {".", false},
209
        {"./", false},
210
        {"lala", false},
211
}
212
 
213
func TestIsAbs(t *testing.T) {
214
        for _, test := range isAbsTests {
215
                if r := IsAbs(test.path); r != test.isAbs {
216
                        t.Errorf("IsAbs(%q) = %v, want %v", test.path, r, test.isAbs)
217
                }
218
        }
219
}

powered by: WebSVN 2.1.0

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