1 // Copyright 2023 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.
14 var joinPathTests = [...]struct {
15 dir, file, path string
18 1: {"./", "./", "./"},
19 2: {"././././", ".", "."},
20 3: {".", "./././", "./"},
22 5: {".", "a/b", "a/b"},
24 7: {".", "../", "../"},
25 8: {".", "../../", "../../"},
26 9: {".", "../..", "../.."},
27 10: {".", "../..//..///", "../../../"},
30 13: {"/", "a/b", "/a/b"},
31 14: {"/a", "b", "/a/b"},
34 17: {"/", "../../", "/"},
35 18: {"/", "/../a/b/c", "/a/b/c"},
36 19: {"/", "/../a/b/c", "/a/b/c"},
37 20: {"/", "./hello/world", "/hello/world"},
38 21: {"/a", "../", "/"},
39 22: {"/a/b/c", "..", "/a/b"},
40 23: {"/a/b/c", "..///..///", "/a/"},
41 24: {"/a/b/c", "..///..///..", "/"},
42 25: {"/a/b/c", "..///..///..///..", "/"},
43 26: {"/a/b/c", "..///..///..///..///..", "/"},
44 27: {"/a/b/c/", "/d/e/f/", "/a/b/c/d/e/f/"},
45 28: {"a/b/c/", ".", "a/b/c"},
46 29: {"a/b/c/", "./d", "a/b/c/d"},
47 30: {"a/b/c/", "./d/", "a/b/c/d/"},
48 31: {"a/b/", "./c/d/", "a/b/c/d/"},
49 32: {"../", "..", "../.."},
50 33: {"a/b/c/d", "e/../..", "a/b/c"},
51 34: {"a/b/c/d", "./e/../..", "a/b/c"},
52 35: {"a/b/c/d", "./e/..//../../f/g//", "a/b/f/g/"},
53 36: {"../../../", "a/../../b/c", "../../b/c"},
54 37: {"/a/b/c", "/.././/hey!", "/a/b/hey!"},
57 func TestJoinPath(t *testing.T) {
58 for _, test := range joinPathTests {
59 t.Run("", func(t *testing.T) {
60 path := syscall.JoinPath(test.dir, test.file)
61 if path != test.path {
62 t.Errorf("join(%q,%q): want=%q got=%q", test.dir, test.file, test.path, path)
68 func BenchmarkJoinPath(b *testing.B) {
69 for _, test := range joinPathTests {
70 b.Run("", func(b *testing.B) {
71 for i := 0; i < b.N; i++ {
72 syscall.JoinPath(test.dir, test.file)