package core import "testing" func TestPathRoot(t *testing.T) { tests := []struct { path Path want string }{ {"", ""}, {"abc", "abc"}, {"abc.def", "abc"}, {"abc.def.ghi", "abc"}, } for _, tt := range tests { if got := tt.path.Root(); got != tt.want { t.Errorf("Path(%q).Root() = %q, want %q", tt.path, got, tt.want) } } } func TestPathSegments(t *testing.T) { tests := []struct { path Path want []string }{ {"", nil}, {"abc", []string{"abc"}}, {"abc.def", []string{"abc", "def"}}, {"abc.def.ghi", []string{"abc", "def", "ghi"}}, } for _, tt := range tests { got := tt.path.Segments() if len(got) != len(tt.want) { t.Errorf("Path(%q).Segments() = %v, want %v", tt.path, got, tt.want) continue } for i := range got { if got[i] != tt.want[i] { t.Errorf("Path(%q).Segments()[%d] = %q, want %q", tt.path, i, got[i], tt.want[i]) } } } }