package urlutil_test

import (
	"testing"

	"source.toby3d.me/toby3d/home/internal/urlutil"
)

func TestShiftPath(t *testing.T) {
	t.Parallel()

	for name, tc := range map[string]struct {
		input, expectHead, expectTail string
	}{
		"root":     {"/", "", "/"},
		"file":     {"/foo", "foo", "/"},
		"dir":      {"/foo/", "foo", "/"},
		"dir-file": {"/foo/bar", "foo", "/bar"},
		"subdir":   {"/foo/bar/", "foo", "/bar"},
	} {
		name, tc := name, tc

		t.Run(name, func(t *testing.T) {
			t.Parallel()

			head, tail := urlutil.ShiftPath(tc.input)
			if head != tc.expectHead {
				t.Errorf("ShiftPath(%s) = '%s', want '%s'", tc.input, head, tc.expectHead)
			}

			if tail != tc.expectTail {
				t.Errorf("ShiftPath(%s) = '%s', want '%s'", tc.input, tail, tc.expectTail)
			}
		})
	}
}
