package util import ( "reflect" "testing" ) func TestSplitPath(t *testing.T) { ok := func(p string, want []string) { got := SplitPath(p) if !reflect.DeepEqual(got, want) { t.Errorf("SplitPath(%q) = %v; want %v", p, got, want) } } ok("", nil) ok("a", []string{"a"}) ok("a/b", []string{"a", "b"}) ok("a/b/c", []string{"a", "b", "c"}) } func TestStripPathPrefix(t *testing.T) { ok := func(long, pref, want string) { got, found := StripPathPrefix(long, pref) if !found { t.Errorf("StripPathPrefix(%s, %s) not found", long, pref) } if got != want { t.Errorf("StripPathPrefix(%s, %s) = %s; want %q", long, pref, got, want) } } bad := func(long, pref string) { got, found := StripPathPrefix(long, pref) if found { t.Errorf("StripPathPrefix(%s, %s) = %s; want not found", long, pref, got) } } ok("a/b/c", "", "a/b/c") ok("a/b/c", "a", "b/c") ok("a/b/c", "a/", "b/c") ok("a/b/c", "a/b", "c") ok("a/b/c", "a/b/", "c") ok("a/b/c", "a/b/c", "") ok("a/b/c", "a/b/c/", "") bad("a/b/c", "b") bad("a/b/c", "a/b/c/d") bad("foo/bar/baz", "foo/baz") bad("foo/bar/baz", "foo/ba") bad("foo/bar/baz", "foo/bart") }