github.com/searKing/golang/go@v1.2.117/path/filepath/path_test.go (about) 1 package filepath_test 2 3 import ( 4 "path/filepath" 5 "strings" 6 "testing" 7 8 filepath_ "github.com/searKing/golang/go/path/filepath" 9 ) 10 11 func TestResolveReference(t *testing.T) { 12 table := []struct { 13 FromBase, ToBase, FromPath, ToPath string 14 }{ 15 { 16 FromBase: "/data/fruits", 17 ToBase: "/data/animals", 18 FromPath: "apple", 19 ToPath: "/data/animals/apple", 20 }, 21 { 22 FromBase: "/data/fruits", 23 ToBase: "/data/animals", 24 FromPath: "/data/fruits/apple", 25 ToPath: "/data/animals/apple", 26 }, 27 { 28 FromBase: "/data/fruits", 29 ToBase: "/data/animals", 30 FromPath: "./apple", 31 ToPath: "/data/animals/apple", 32 }, 33 { 34 FromBase: "/data/fruits", 35 ToBase: "/data/animals", 36 FromPath: "/data/stars/moon", 37 ToPath: "/data/stars/moon", 38 }, 39 { 40 FromBase: "./data/fruits", 41 ToBase: "/data/animals", 42 FromPath: "/data/stars/moon", 43 ToPath: "/data/animals/data/stars/moon", 44 }, 45 } 46 for i, test := range table { 47 toPath := filepath_.ResolveReference(filepath.FromSlash(test.FromPath), filepath.FromSlash(test.FromBase), filepath.FromSlash(test.ToBase)) 48 if !strings.EqualFold(filepath.ToSlash(toPath), test.ToPath) { 49 t.Errorf("#%d. got %q, want %q", i, toPath, test.ToPath) 50 } 51 } 52 }