]> Cypherpunks.ru repositories - gostls13.git/blob - src/syscall/fs_wasip1_test.go
cmd/compile/internal/inline: score call sites exposed by inlines
[gostls13.git] / src / syscall / fs_wasip1_test.go
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.
4
5 //go:build wasip1
6
7 package syscall_test
8
9 import (
10         "syscall"
11         "testing"
12 )
13
14 var joinPathTests = [...]struct {
15         dir, file, path string
16 }{
17         0:  {".", ".", "."},
18         1:  {"./", "./", "./"},
19         2:  {"././././", ".", "."},
20         3:  {".", "./././", "./"},
21         4:  {".", "a", "a"},
22         5:  {".", "a/b", "a/b"},
23         6:  {".", "..", ".."},
24         7:  {".", "../", "../"},
25         8:  {".", "../../", "../../"},
26         9:  {".", "../..", "../.."},
27         10: {".", "../..//..///", "../../../"},
28         11: {"/", "/", "/"},
29         12: {"/", "a", "/a"},
30         13: {"/", "a/b", "/a/b"},
31         14: {"/a", "b", "/a/b"},
32         15: {"/", ".", "/"},
33         16: {"/", "..", "/"},
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!"},
55 }
56
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)
63                         }
64                 })
65         }
66 }
67
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)
73                         }
74                 })
75         }
76 }