LEFT | RIGHT |
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 "io/ioutil" | 8 "io/ioutil" |
9 "os" | 9 "os" |
10 "path/filepath" | 10 "path/filepath" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 {`\\i\..\c$`, `\c$`}, | 84 {`\\i\..\c$`, `\c$`}, |
85 {`\\i\..\i\c$`, `\i\c$`}, | 85 {`\\i\..\i\c$`, `\i\c$`}, |
86 {`\\i\..\I\c$`, `\I\c$`}, | 86 {`\\i\..\I\c$`, `\I\c$`}, |
87 {`\\host\share\foo\..\bar`, `\\host\share\bar`}, | 87 {`\\host\share\foo\..\bar`, `\\host\share\bar`}, |
88 {`//host/share/foo/../baz`, `\\host\share\baz`}, | 88 {`//host/share/foo/../baz`, `\\host\share\baz`}, |
89 {`\\a\b\..\c`, `\\a\b\c`}, | 89 {`\\a\b\..\c`, `\\a\b\c`}, |
90 {`\\a\b`, `\\a\b`}, | 90 {`\\a\b`, `\\a\b`}, |
91 } | 91 } |
92 | 92 |
93 func TestClean(t *testing.T) { | 93 func TestClean(t *testing.T) { |
94 const N = 100 | |
95 | |
96 tests := cleantests | 94 tests := cleantests |
97 if runtime.GOOS == "windows" { | 95 if runtime.GOOS == "windows" { |
98 for i := range tests { | 96 for i := range tests { |
99 tests[i].result = filepath.FromSlash(tests[i].result) | 97 tests[i].result = filepath.FromSlash(tests[i].result) |
100 } | 98 } |
101 tests = append(tests, wincleantests...) | 99 tests = append(tests, wincleantests...) |
102 } | 100 } |
103 for _, test := range tests { | 101 for _, test := range tests { |
104 if s := filepath.Clean(test.path); s != test.result { | 102 if s := filepath.Clean(test.path); s != test.result { |
105 t.Errorf("Clean(%q) = %q, want %q", test.path, s, test.r
esult) | 103 t.Errorf("Clean(%q) = %q, want %q", test.path, s, test.r
esult) |
106 } | 104 } |
107 if s := filepath.Clean(test.result); s != test.result { | 105 if s := filepath.Clean(test.result); s != test.result { |
108 t.Errorf("Clean(%q) = %q, want %q", test.result, s, test
.result) | 106 t.Errorf("Clean(%q) = %q, want %q", test.result, s, test
.result) |
109 } | 107 } |
110 } | 108 } |
111 | 109 |
112 for _, test := range tests { | 110 for _, test := range tests { |
113 » » allocs := testing.AllocsPerRun(N, func() { | 111 » » allocs := testing.AllocsPerRun(100, func() { filepath.Clean(test
.result) }) |
114 » » » filepath.Clean(test.result) | |
115 » » }) | |
116 if allocs > 0 { | 112 if allocs > 0 { |
117 t.Errorf("Clean(%q): %v allocs, want zero", test.result,
allocs) | 113 t.Errorf("Clean(%q): %v allocs, want zero", test.result,
allocs) |
118 } | 114 } |
119 } | 115 } |
120 } | 116 } |
121 | 117 |
122 const sep = filepath.Separator | 118 const sep = filepath.Separator |
123 | 119 |
124 var slashtests = []PathTest{ | 120 var slashtests = []PathTest{ |
125 {"", ""}, | 121 {"", ""}, |
(...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
910 return filepath.SkipDir | 906 return filepath.SkipDir |
911 case src: | 907 case src: |
912 seenSrc = true | 908 seenSrc = true |
913 } | 909 } |
914 return nil | 910 return nil |
915 }) | 911 }) |
916 if !seenSrc { | 912 if !seenSrc { |
917 t.Fatalf("%q not seen", src) | 913 t.Fatalf("%q not seen", src) |
918 } | 914 } |
919 } | 915 } |
LEFT | RIGHT |