Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 85aad2b

Browse files
author
Openset
committed
Add: Simplify Path
1 parent f9e02de commit 85aad2b

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

‎problems/simplify-path/simplify_path.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
11
package simplify_path
2+
3+
import "path/filepath"
4+
5+
func simplifyPath(path string) string {
6+
return filepath.Clean(path)
7+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,43 @@
11
package simplify_path
2+
3+
import "testing"
4+
5+
type caseType struct {
6+
input string
7+
expected string
8+
}
9+
10+
func TestSimplifyPath(t *testing.T) {
11+
tests := [...]caseType{
12+
{
13+
input: "/home/",
14+
expected: "/home",
15+
},
16+
{
17+
input: "/../",
18+
expected: "/",
19+
},
20+
{
21+
input: "/home//foo/",
22+
expected: "/home/foo",
23+
},
24+
{
25+
input: "/a/./b/../../c/",
26+
expected: "/c",
27+
},
28+
{
29+
input: "/a/../../b/../c//.//",
30+
expected: "/c",
31+
},
32+
{
33+
input: "/a//b////c/d//././/..",
34+
expected: "/a/b/c",
35+
},
36+
}
37+
for _, tc := range tests {
38+
output := simplifyPath(tc.input)
39+
if output != tc.expected {
40+
t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected)
41+
}
42+
}
43+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /