@@ -137,3 +137,28 @@ func TestPath_Name(t *testing.T) {
137137 })
138138 }
139139}
140+
141+ func TestPathHasPrefix (t * testing.T ) {
142+ tests := []struct {
143+ name string
144+ path Path
145+ other Path
146+ want bool
147+ }{
148+ {"empty both" , NewPath ("" ), NewPath ("" ), true },
149+ {"empty other" , NewPath ("foo" ), NewPath ("" ), true },
150+ {"empty path" , NewPath ("" ), NewPath ("foo" ), false },
151+ {"equal" , NewPath ("foo" ), NewPath ("foo" ), true },
152+ {"prefix" , NewPath ("foo:bar" ), NewPath ("foo" ), true },
153+ {"string prefix only" , NewPath ("foooo:bar" ), NewPath ("foo" ), false },
154+ {"not prefix" , NewPath ("foo" ), NewPath ("foo:bar" ), false },
155+ {"other ending in :" , NewPath ("foo:bar" ), NewPath ("foo:" ), true }, // "foo:" is not a valid path, but we should have a defined behaviour
156+ }
157+ for _ , tt := range tests {
158+ t .Run (tt .name , func (t * testing.T ) {
159+ if got := tt .path .HasPrefix (tt .other ); got != tt .want {
160+ t .Errorf ("HasPrefix() = %v, want %v" , got , tt .want )
161+ }
162+ })
163+ }
164+ }
0 commit comments