github.com/Schaudge/grailbase@v0.0.0-20240223061707-44c758a471c0/file/path_test.go (about) 1 package file_test 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/Schaudge/grailbase/file" 8 "github.com/grailbio/testutil/expect" 9 ) 10 11 func TestJoin(t *testing.T) { 12 tests := []struct { 13 elems []string 14 want string 15 }{ 16 { 17 []string{"foo/"}, // trailing separator removed from first element. 18 "foo", 19 }, 20 { 21 []string{"foo", "bar"}, // join adds separator 22 "foo/bar", 23 }, 24 { 25 []string{"foo", "bar/"}, // trailing separator removed from second element. 26 "foo/bar", 27 }, 28 { 29 []string{"/foo", "bar"}, // leading separator is retained in first element. 30 "/foo/bar", 31 }, 32 { 33 []string{"foo/", "bar"}, // trailing separator removed before join. 34 "foo/bar", 35 }, 36 { 37 []string{"foo/", "/bar"}, // all separators removed before join. 38 "foo/bar", 39 }, 40 { 41 []string{"foo/", "/bar", "baz"}, // all separators removed before join. 42 "foo/bar/baz", 43 }, 44 { 45 []string{"foo/", "bar", "/baz"}, // all separators removed before join. 46 "foo/bar/baz", 47 }, 48 { 49 []string{"http://foo/", "/bar"}, // separators inside the element are retained. 50 "http://foo/bar", 51 }, 52 { 53 []string{"s3://", "bar"}, 54 "s3://bar", 55 }, 56 { 57 []string{"s3://", "/bar"}, 58 "s3://bar", 59 }, 60 { 61 []string{"//go/src/Schaudge/grailbase/file", "path_test.go"}, 62 "//go/src/Schaudge/grailbase/file/path_test.go", 63 }, 64 } 65 for i, test := range tests { 66 t.Run(fmt.Sprint(i), func(t *testing.T) { 67 expect.EQ(t, file.Join(test.elems...), test.want) 68 }) 69 } 70 }